Sorry for the new questions... I've created this program to display a table . How could I write this code using while statements instead of for?

#include <iostream>

using namespace std;

int main()
{
	for (int x = 1; x < 4; x++ )
	{ 
		cout << x << " ";
		for (int y = 0; y < 10; y++)
		{

			cout << x* y << " ";
			

		} //end for

		cout << endl;
	} //end for
	cout << endl;
		system ("pause");
	return 0;


} //end of main function
start x at 1
while x less than 4
  display x
  start y at 0
  while y less than 10
    display result of x times y followed by a space
    increment y by one
  start a new line
  increment x by 1

Edited 6 Years Ago by Lerner: n/a

This seems so easy but I still cannot get it.. any help to point me in the right direction would be much appreciated. Oh and the reason I have to bother changing it to while loops is just for homework... The for loops make so much more sense in this case.

Thanks!

#include <iostream>

using namespace std; // So we can see cout and endl

int main()
{ 
  int x = 1;  // Don't forget to declare variables
  while ( x < 4 ) 
  { // While x is less than 4
    cout<< x <<endl;
    int y = 0;             // Update x so the condition can be met eventually
	while ( y < 10 )
	{
		cout << x*y << endl;
		y++;
	}
	cout << endl;
	x++;
  }
  cout << endl;
  cin.get();
}

Edited 6 Years Ago by creative9k: n/a

#include <iostream>

using namespace std; // So we can see cout and endl

int main()
{ 
  int x = 1;  // Don't forget to declare variables
  while ( x < 4 ) 
  { // While x is less than 4
    cout<< x << " ";
    int y = 0;             // Update x so the condition can be met eventually
	while ( y < 10 )
	{
		cout << x*y<< " ";
		y++;
	}
	cout << endl;
	x++;
  }
  cout << endl;
  cin.get();
}
This question has already been answered. Start a new discussion instead.