我需要检查,如果他们输入高兴,伤心或生气时提示: 输入一个心情(快乐,悲伤,生气) 这是我为它至今 计数代码= 0; 一段时间(数< 1){C++检查,如果用户输入一个有效的答案
cout << ", How are you feeling today? (happy,sad,mad)" << endl;
cin >> mood;
if (mood == sad){
cout << "im sorry you're feeling sad" << endl;
count++;
}
else if (mood == happy) {
cout << "I'm glad you're feeling happy!" << endl;
count++;
}
else if (mood == mad){
cout << "Don't be angry, there's so many happy things in life!" << endl;
}
else{
cout << " invalid input " << endl;
count = 0;
}
}
,但如果我把高兴,伤心或生气它只是在无效的输入。 我也试过为他们声明字符串变量,如 string happy = happy; string sad = sad; string mad = mad;
看起来您正在混淆变量名和文本字符串。他们可能是同一个词,但它们是无关的。 (例如,除非mad是一个值为“mad”的std :: string)。 –
这是如何编译的?发布一个MCVE。 –
你应该使用双引号来表示一个字符串。做到这一点,一切都应该在世界上。直到下一个错误。 – user4581301