Nov 4, 2019 at 7:37pm UTC
Hi, I"m writing a program to acquire an amount and reject anything less than 1000. Also have to make sure program quits if 0 is the input.
double amount = 0;
cout << "mount: ";
cin >> amount;
while (true) {
if (amount < 1000) {
cout << "can't be less than 1000." << endl; break;
} if (amount != 0) {
cout << "Bye!" << endl; break;
}
}
Nov 4, 2019 at 7:55pm UTC
was there a question in there?
it seems like you should modify amount in the loop somewhere?
its also convoluted -- you usurped the condition of the while to inject it into the loop body via a break. Any reason?
Last edited on Nov 4, 2019 at 7:56pm UTC
Nov 4, 2019 at 10:14pm UTC
Hello kmoua123,
I think what you are trying to do is this:
double amount = 0;cout << "mount: " ;cin >> amount;while (true ){if (amount == 0){cout << "Bye!" << endl; break ;}if (amount < 1000){cout <<"can't be less than 1000." << endl; break ;}}
You left to much white space in your code.
Andy
Nov 5, 2019 at 2:51pm UTC
Thank you all for the input! It has be very helpful and I think I have it figured out now.