Using two for statements

I need to display a table consisting of four rows and 11 columns that should resemble the table below. The second and following columns should multiply the number in the first column by the numbers 0-9. I have to use two for statements in my code.

1 0 1 2 3 4 5 6 7 8 9
2 0 2 4 6 8 10 12 14 16 18
3 0 3 6 9 12 15 18 21 24 27
4 0 4 8 12 16 20 24 28 32 36

I am LOST! I have searched all the forums and online and can't get this to work for me. I'm not to concerned about alignment at this point, I just need to get this to work.

#include <iostream>
using namespace std;

int main()
{
//declare variables
int multiplicand = 1;
int product = 0;

cout << product;
cin >> multiplicand;

while (multiplicand >= 0)
{
for (int multiplier = 1; multiplier <9;
multiplier += 1)
{
product=multiplicand * multiplier;
cout << multiplicand<<multiplier<<product<<endl;
} //end for

} // end while

system("pause");
return 0;
} //end of main function

Am I anywhere close??
Thanks for your help in advance!!
Replace the while with:
for(multiplicand=1;multiplicand<5;multiplicand++)
Make sure you match up your brackets.
Remember that
for(xxx;yyy;zzz)aaa;
is the same as:
1
2
3
4
5
xxx;
while(yyy){
aaa;
zzz;
}

Ok, I was totally off base and I can achieve my results below but using only one for statement, can anyone tell me how to use two for statements to achieve the same table?

Thanks again,


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

int main()
{
//declare variables
int number = 1;

while (number < 5)
{
//Using the for statement

cout << number << ' ';
for (int x =0; x <= 9; x += 1)
cout << number * x << ' ';

//end for
number += 1;
cout << endl;
}
//end while

system("pause");
return 0;
} //end of main function
step-by-step:
delete number += 1; and int number =1;
replace while (number < 5) with for(int number=1;number<5;number++)
you see we have simplified the logic by putting all the info about the iteration on one line.
Last edited on
Great!! Below is what I coded per your instructions and it gave me the results I needed.
Thanks so much!! Is there anything wrong with the format below? Also how could I align the tables?

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

int main()
{
//declare variables
int number = 1;

for (int number = 1; number < 5; number += 1)
{
//Using the for statement

cout << number << ' ';
for (int x =0; x <= 9; x += 1)
cout << number * x << ' ';

//end for

cout << endl;
}
//end while

system("pause");
return 0;
} //end of main function
Sorry, here is the final version, can u tell me if anything else is wrong with the format? And how to align the tables?

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

int main()
{
//Using the for statement
for (int number = 1; number < 5; number ++)
{

cout << number << ' ';
for (int x =0; x <= 9; x += 1)
cout << number * x << ' ';

//end for

cout << endl;
}

system("pause");
return 0;
} //end of main function
Topic archived. No new replies allowed.