【发布时间】:2022-09-28 15:04:21
【问题描述】:
我要求用户输入进行投资,如果输入 < 0 或 cin.fail() 我有一个 while 循环条件,当我运行代码并输入 \'g\' 时,它会抛出 cout 语句的无休止输出.我究竟做错了什么 ?
cin >> investment;
while ((!(investment >= 0)) || cin.fail()) {
cout << \"Please enter an amount $0 or more\" << endl;
cout << \"Initial Investment Amount: $\";
cin >> investment;
}
标签: c++