#include <iostream>
usingnamespace std;
int main()
{
int x = 0;
int y = 9;
do
{
cout << "x * y = " << (x * y) << endl;
x++;
cin.get();
}
while ( x == 6);
{
system("PAUSE");
cin.get();
}
}
The problem is that it only displays x * y = 0, instead of all the multiplications, until x = 5. What am i doing wrong? Wasnt that supposed to be correct? Please help ...
#include <iostream>
usingnamespace std;
int main()
{
int x = 0;
int y = 9;
while (x<6)
{
cout << "x * y = " << (x * y) << endl;
x++;
cin.get();
}
system("PAUSE");
cin.get();
return 0;
}
should do the trick for you.
the do-while loop in your example continues for as long as x==6 which means x equals six. The comparision expression gets evaluated after the loop is passed for the first time, on which point x==1;
this means that the loop does not continue, since the result of x==6 is false.
x<6 results in true for every value below 6. The loop continues as long as the expression returns true, so at the moment x becomes 6 it ends.
hmm, understood... I thought that , in this case, the program would execute whats within do, and when x = 6 it would stop. Exactly the opposite seymore said...:D Thank you all, im new to this