output numbers and squares

sorry for being such a nuisance, but now I have numbers and their squares between 1 & 10. can anyone help, i have-

#include <iostream>
using namespace std;
void main()

{
int i;
i = 1;
while(i <= 10)
cout << i * i << endl;
i++;
}
sorry for being such a nuisance, but now I have *to output* numbers and their squares between 1 & 10.
closed account (D80DSL3A)
You are not a nuisance. Many of us come here to answer questions like yours for entertainment. I'm glad this is such an active board.

Are you getting an endless column of 1's ?
You forgot to wrap both instructions after the while() in curly braces {};
1
2
3
4
5
while(i <= 10)
{
    cout << i * i << endl;
    i++;
}

That puts the i++; statement inside the while() loop.
Just modify the cout <<... line if you want to display something else on each line.
oh ok.

and yes, i had an infinite loop.
i did what you said by putting the curly brace after the while loop.
now i have an error at the while().
this is what I have-

#include <iostream>
using namespace std;
void main()

{
int i;
i = 1

while(i <= 10) //i have an error at this line
{
cout << i * i << endl;
i++;
}
closed account (D80DSL3A)
Actually, the error is at the line before that.
Topic archived. No new replies allowed.