我是新手,请帮忙。我正在尝试编写一个由教授做的练习的程序,我的教授列出了程序的外观,我遵循了这些步骤,但是身体仍然没有执行。我尝试了传统的while循环和do ... while循环以获取所需的答案,但是当我输入7或更高时,主体将无法执行。
直板售价为1美元,每个直板都有一张优惠券,而7张优惠券可以得到一个直板。
#include <iostream>
sing namespace std;
int main() {
int candyBars, money, coupons, bonus, couponsLeft;
cout << "How much money do you have? ";
cin >> money;
candyBars = money;
coupons = candyBars;
do
{
bonus = coupons / 7;
couponsLeft = coupons % 7;
}while(candyBars >= 7);
cout << ("You can buy ") << candyBars + bonus << (" and you will have ") <<
couponsLeft << " left over." ;
system("Pause");
return 0;
}
经过深思熟虑并感谢您的所有贡献,这就是我想出的:
do
{
candyBars = money;
coupons = candyBars;
bonus = coupons / 7;
couponsLeft = coupons % 7;
cout << ("You can buy ") << candyBars + bonus << (" and you will have ")
<< couponsLeft << " left over. \n\n" ;
cout << "How much money do you have? ";
cin >> money;
}while(money != 000);
cout << ("You can buy ") << candyBars + bonus << (" and you will have ") <<
couponsLeft << " left over.\n" ;