#include <stdio.h>
int main(void)
{
char fever, cough; /*Sets the chars.*/
printf("Are you running a fever? (y/n)\n"); /*Asks if they have a fever and saves their input.*/
scanf("%c",&fever);
printf("Do you have a runny nose/cough? (y/n)\n"); /*Asks if they have a cough and saves their input.*/
scanf(" %c",&cough);
printf("Please verify the folling information.\nFever: %c \nRunny nose/cough: %c \n",fever,cough); /*Asks if the following info is correct.*/
if ((fever=y) && (cough=y))
printf("Your recommendation is to see a doctor.");
else if ((fever=n) && (cough=y))
printf("Your recommendation is to get some rest.");
else if ((fever=y) && (cough=n)
printf("Your recommendation is to see a doctor.");
else
printf("Your are healthy.");
return 0;
}
我有y和n的错误
最佳答案
(fever=y)
是作业。
你需要(fever == 'y')
注意'
(引号),还有条件检查==
而不是=
这件事每次都要解决。
if ((fever == 'y') && (cough == 'y')) {
printf("Your recommendation is to see a doctor.");
}
else if ((fever == 'n') && (cough == 'y')) {
printf("Your recommendation is to get some rest.");
}
else if ((fever == 'y') && (cough == 'n') {
printf("Your recommendation is to see a doctor.");
}
关于c - C语言是否,如果用字符声明?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19107067/