Mar 30, 2014 at 10:57pm Mar 30, 2014 at 10:57pm UTC
Okay, yet another question. This time, it has to do with while loops. Let me paste the code first.
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
#include <iostream>
#include <string>
using namespace std;
int main()
{
string userselection = "no" ;
while (userselection == "yes" )
{
cout << "Enter two numbers: " << endl;
int num1 = 0;
int num2 = 0;
cin >> num1;
cin >> num2;
cout << num1 << " X " << num2 << " = " << num1 * num2 << endl;
cout << "Press 'yes' to redo operation, any other to exit! " << endl;
cin >> userselection;
}
cout << "Goodybe" << endl;
return 0;
}
When I execute this, it doesn't even execute the codes inside the second braces. When I add a semicolon after the while statement, the braces execute, however the loop won't happen. Help me out here?
Last edited on Mar 30, 2014 at 10:59pm Mar 30, 2014 at 10:59pm UTC
Mar 30, 2014 at 11:00pm Mar 30, 2014 at 11:00pm UTC
Why do you think it would execute?
Mar 30, 2014 at 11:02pm Mar 30, 2014 at 11:02pm UTC
The semicolon ends the while expression, therefore moving on to the next set of code.