Your code will output 2*number, it will not double number for the next round. Also, the continue in your if statement isn't used correctly. Try something like this:
1 2 3 4 5 6 7 8 9 10 11
while(true)
{
cout << "continue ? (y/n)";
cin >> choice;
if (choice != 'y') break;
if (choice != 'n') continue;
number *= 2;
cout << number;
}
if (choice != 'y') break;
if (choice != 'n')
{
number *= 2;
cout << number;
}
}
'continue' will continue to the next iteration of the loop without executing further statements.
if (choice != 'n') continue;
This will go to the while loop again and check the condition again.
So
number *= 2;
cout << number;
is never executed in case we use continue.
How do I make it that my number doubles every time I hit Y ?
1 2 3 4 5 6 7 8 9 10 11 12 13 14
{
number=2
cout << "continue ? (y/n)";
cin >> choice;
if (choice != 'y') break;
while (number==y; y++) //not sure how to properly use this
if (choice != 'n')
{
number *= 2;
cout << number;
}
i want my number to double for every (y) until i hit (n)
This is what you need. Added comments at the places I modified your program.
int main()
{
int number;
char choice; //choice should be char and not int, to compare it properly
with 'y' or 'Y'
number=2; //so that it does not reassign it to 2 each time the loop iterates.
if (choice != 'y' && choice != 'Y') break; //Added additional 'Y' to ensure y and Y both are accepted
else
{
number *= 2;
cout << number<<endl;
}
}
system("PAUSE");
return EXIT_SUCCESS;
}
How do you know its not doubling ?
cout << pi<<endl<<endl; you are only printing pi, whose value is not changed.
print n also and check.
cout << n<<endl;
Your program works for me.