C++ While Loop Using If Statments

Hi, I am trying to create a multiplication table (5x10) using a while loop and if statements. I can't seem to get rid of the output of the 5 0's in a row.

Here is my code so far.

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
//Declare Variables
int x=0, y=0, product;

//Order/Number the Columns and Rows
while(x+y<=15)
{
if(x==6)
{
x=x-5;
y++;

//Output the Zero Column of Data
cout << endl << setw(3) << y;
}
//Counts Up for The Columns
if(x==0)

//Display the First Row of Data
cout << setw(3) << " 0" << " " << " 1" << " " << " 2" << " " << " 3" << " " << " 4" << " " << " 5" << " ";

//Mathematics Using Declared Variables
product=x++*y;

cout << setw(3) << product;
}
//End the While Loop
cout << endl << endl;

return(0);
}
//End Main





Can someone show me how to get rid of the 5 output 0's in the output line 1?

Thanks in advance!
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
26
27
28
29
30
31
32
33
34
35
36
37
#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
	//Declare Variables
	int x=0, y=0, product;

	//Order/Number the Columns and Rows
	while(x+y<=15)
	{
		if(x==6)
		{
			x=x-5;
			y++;

			//Output the Zero Column of Data
			cout << endl << setw(3) << y;
		}
		//Counts Up for The Columns
		if(x==0)

			//Display the First Row of Data
			cout << setw(3) << " 0" << " " << " 1" << " " << " 2" << " " << " 3" << " " << " 4" << " " << " 5" << " ";

		//Mathematics Using Declared Variables
		product=x++*y;
		if (product != 0)
			cout << setw(3) << product;
	}
	//End the While Loop
	cout << endl << endl;

	return(0);
}
//End Main 


Notice line 29
Last edited on
Thank you very much JMJAtlanta!

You're the best!
Topic archived. No new replies allowed.