我正在编写一个程序,输出一个递增的整数,直到达到400。即使添加的“ while”少于400 in,它也总是经过一次。有任何建议可以解决吗?
cout << "enter population of US at end of last year (in millions): ";
cin >> USpop;
do {
USpop = USpop * 1.01007;
year = year +1;
cout<< " " << year << " " << setprecision(1) << fixed << USpop <<endl;
} while (USpop < 400);
答案 0 :(得分:2)
也许是这样吗?
while((USpop *= 1.01007) < 400)
{
year = year + 1;
cout << " " << year << " " << fixed << USpop << endl;
}