C语言是或否如果带有char的语句?

J T*_*J T 0 c if-statement char

#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;
}
Run Code Online (Sandbox Code Playgroud)

我得到y和n的错误

kar*_*ikr 7

(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.");
}
Run Code Online (Sandbox Code Playgroud)