#include <stdio.h>
//function prototypes
const double fiveNinths = 5/9;
int toCelsius(double value)
{
return ((value - 32) * (fiveNinths));
}
int toFarenheit(double value)
{
return (value * 1.8) + 32;
}
int main (void)
{
int intValue, menuSelect;
double results;
intValue = 1;
while (intValue > 0)
{
printf("enter a positive integer: \n");
scanf("%d", &intValue);
if (intValue > 0)
{
printf("Enter 1 to convert to Farenheit, enter 2 to convert to Celsius: \n");
scanf("%d", &menuSelect);
if (menuSelect == 1)
{
results = toFarenheit(intValue);
printf("%d degrees to Farenheit is %d\n", intValue, results);
}
else if (menuSelect == 2)
{
results = toCelsius(intValue);
printf("%d degrees to Celsius is %d\n", intValue, results);
}
else
{
printf("invalid menu item, please input only 1 or 2\n");
}
}
}
return 0;
}
toCelsiusの値が常に0を返す理由がわかりません。私のtoFarenheit関数はうまく動作します。また、このプログラムは、ユーザーに負の整数値を入力させることによって終了します。それは宿題の一部です。その部分を無視してください。私の関数は、実際に計算された戻り値の代わりに0を返し続けますか?
[mcve]の提供方法をお読みください。あなたの質問には、あなたの主張をサポートするための入力/出力値がありません。 – user694733
コードを正しくフォーマットしてください。 –
ヒント:Cで5/9とは何ですか? –