Reputation: 1
I am making a program that outputs an increasing integer until it reaches 400. Even when less than 400 in for "while" is added, it always goes over once. Any Suggestions to fix?
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);
Upvotes: 0
Views: 84
Reputation: 1168
Maybe like this?
while((USpop *= 1.01007) < 400)
{
year = year + 1;
cout << " " << year << " " << fixed << USpop << endl;
}
Upvotes: 2