ok, some issues.
"No" -- strings in c++ have double quotes. single quotes are for characters. It compiles but it may not be doing what you think, be careful with this.
why do you ask the same thing twice, if its no or no? (line 28). you only need to check once.
the break is incorrect. you break ALL THE TIME. I believe you want to break only if they said NO. The break should be INSIDE the {} with the if no statement, then!
you never change count. so why 500? get rid of count, you don't need it (its not wrong, its just cluttery):
a forever loop:
while(true)
{
if(something) break; //the only way out
}
fixing the break will fix the original question you had. Also be sure to REMOVE THE ; on the IF STATEMENT for NO, this is incorrect. I see that choice is a char, so instead of "No" you do want single quotes, 'N' perhaps? Either make it a string and want "No" or keep it a char and want 'N' but fix this one way or the other.
but, you should not perhaps do the work (print the even values?) if they entered 10042?
as it stands, bad values will still print the evens. Is that what you wanted?
anyway, my quick edits to repair it:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
#include <iostream>
using namespace std;
int main()
{
//Ask the user for a number between 0 and 501
int number;
char choice;
int count = 1;
while (count < 500)
{
cout << "Enter a number between 0 and 501: ";
cin >> number;
if (number < 1 || number > 500)
{
cout << "\nOUT OF RANGE!"; "\n";
}
//consider:
else {
for (int i = 0; i <= number; i += 2)
cout << i << ' ';
cout << "\n";
} //end of else idea
// Ask if theyd like to enter another number
cout << "Would you like to enter another number? (Yes/No)" << endl;
cin >> choice;
if (choice == 'N')
{cout << "Goodbye!"; break;}
}
return 0;}
|