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.
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:
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.
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