looking for a lil help

this code should give a table consisting of 4 rows and 6 columns.
1st column should give 1-4.
2nd column should give the result of raising the number in the 1st column by the pow of 2. and so on and so on. I was able to do this with the for loop, but, I can not get it to work with 2 while statements. here is what I have and it gives this in the out put:
1 1 1 1 1 1
2
3
4
and this is what it is ment to look like:
1 1 1 1 1 1
2 4 8 16 32 64
3 9 27 81 243 729
4 16 64 256 1024 4096
Here is the code:
#include <iostream>
#include <cmath>

using namespace std;


int main()
{
int xVar = 1; //counter
double yVar = 0.0; //accumulator

while (xVar < 5)
{
cout << xVar << " ";
while (yVar < 5)
{
cout << pow(xVar, yVar) << " ";
yVar +1; //accumulator
} //end while
cout << endl;
xVar +=1; //counter
} //end while
cout << endl;


system("pause");
return 0;

} //end of main function

what did I miss??????
Last edited on
what did I miss??????

An equals sign.

yVar +1; //accumulator

EDIT: OK I ran your program and that wasn't your problem (it produces an infinite loop without the equals sign).

Your issue is that you need to set yVar back to zero before the while (yVar < 5) loop. Also, why are you printing xVar? If you're printing xVar (i.e. xVar to the power of one), you might as well start yVar at 2.
Last edited on
Topic archived. No new replies allowed.