我知道 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!");
}
最佳答案
The objective is to make this if/else statement work,
您的代码中缺少花括号。
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");
}
关于c - C 语言中 else 没有前面的 if,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42048183/