提问人:user22792016 提问时间:10/24/2023 最后编辑:Remy Lebeauuser22792016 更新时间:10/24/2023 访问量:84
If 和 else 语句没有按预期的方式工作
If and else statement is not working as how its supposed to
问:
作为初学者编码员,我只是在玩一些代码。我遇到了一个问题,无论我输入什么,它都会运行我的部分。发生这种情况是有原因的吗?else
我试着这样做,如果我以某种方式回应,它就会输出下一个短语。
#include <iostream>
int main() {
std::string answer;
std::cout << "Get up on the floor!" << std::endl;
std::cin >> answer;
int a = false;
if (answer == "Dancin' all night long") {
std::cout << "get up on the floor!" << std::endl;
} else {
int g = false;
while (g == false) {
std::cout << "Try again." << std::endl;
std::cin >> answer;
if (answer == "Dancin' all night long") {
int g = true;
std::cout << "get up on the floor!" << std::endl;
}
}
}
return 0;
}
答: 暂无答案
评论
>>
std::getline
int g = true;
g
g
while
true
false
int
bool