如果投标金额少于所需金额,我不知道如何循环或重复cin >> cashTendered
。
到目前为止,这就是我所拥有的。
if (cashTendered > || == total)
{
cout << "Your change is: $" << fixed << setprecision(2) << change << ".\n\n"
<< "Have a great day!\n\n\n\n\n";
}
else
{
cout << "You did not tender enough money to cover the total cost.\n"
<< "Please enter amount of cash tendered: $";
}
所以现在我想要if语句重复,直到为真。
有什么建议吗?
答案 0 :(得分:0)
while(true)
{
cin >> cashTendered
if (cashTendered >= total)
{
cout << "Your change is: $" << fixed << setprecision(2) << change << ".\n\n"
<< "Have a great day!\n\n\n\n\n";
break;
}
else
{
cout << "You did not tender enough money to cover the total cost.\n"
<< "Please enter amount of cash tendered: $";
}
}
答案 1 :(得分:0)
看看loops in c++。此外,如果条件可以缩短为>=
而不是> || ==
。此外,既然你想重复,直到cashTendered为&gt; = total,你需要一个循环来检查条件,如果cashTendered是&lt;总
while (cashTendered < total)
{
cout << "You did not tender enough money to cover the total cost.\n"
<< "Please enter amount of cash tendered: $";
cin >> cashTendered;
}
cout << "Your change is: $" << fixed << setprecision(2) << change << ".\n\n"
<< "Have a great day!\n\n\n\n\n";