我正在用C编写一个程序,要求用户输入一个等级7天的温度,程序会将这些温度转换为相反的温度。请注意,当用户输入华氏温度时,我也应该写这个案例,但我还没有。
#include <stdio.h>
#define N 7
float CELC(float x)
{
float c;
c = (x*(9.0/5.0))+32;
}
void TempConverter(void)
{
char cmd;
float x, b, c, dayc[N], dayf[N];
int i;
printf("\nHello, this program converts the temperatures of the last week from one scale to another.\n");
printf("\nWhat is the scale of the temperature degrees you want to enter?\n");
printf("\nPlease enter f for Fahrenheit and c for Celsius:\n\n");
scanf_s("%c", &cmd);
if (cmd == 'c')
{
for (i = 1; i < 8; i++)
{
printf("\nPlease enter the temperature of day %d: ", i);
scanf_s("%f", &dayc[i]);
if (dayc[i] > 60.0 || dayc[i] < -50.0)
{
printf("\nThis is an invalid temperature, please enter a different value\n");
--i;
continue;
}
dayc[i] = CELC(dayc[i]);
}
printf("\nYour equivalent Fahrenheit temperatures are as follows:\n");
for (i = 0; i < N; i++)
{
printf("\nThe temperature of day %d:%f\n", i+1, dayc[i]);
}
}
}
出于某种原因,我一直收到运行时错误,然后我已经转换为华氏温度的温度变得怪异。我很确定这个问题与我对dayc的使用有关,但我不知道该怎么办。