我理解else语句不应该在if语句的末尾加上分号。
目标是使这个if / else语句有效,这样如果答案不是Y或y,那么打印else语句。我的问题是:
以下是代码:
if (answer=='Y'|| 'y')
scanf(" c", &answer);
printf("\n Great! Keep listening to music. I'm sure your mood will improve.");
else printf("\n Try listening to some music that you enjoy!");
}
答案 0 :(得分:1)
目标是使这个if / else语句有效,
您缺少代码中的花括号。
scanf(" %c", &answer);
if (answer=='Y'|| answer == 'y') {
printf("\nGreat! Keep listening to music. I'm sure your mood will improve.\n");
}
else {
printf("\nTry listening to some music that you enjoy!\n");
}