7th Oct 2017, 7:13 AM
Alan Tao
Alan Tao - avatar
5 Answers
+ 16
Try outputting an endl at the end of your cout statement, so every equation is on its own line. A space between the operands and the "x" could also look nice, like what you do with the "=". Ex: cout << y << " x " << x << " = " << (y * x) << endl; Result: 1 x 1 = 1 2 x 1 = 2 //etc. Also, at the top of the first for, you can make a header that displays which number you're multiplying. Ex: cout << x + "'s Multiplication" << endl; Result: 1's Multiplication 1 x 1 = 1 //... 2's Multiplication 1 x 2 = 2
7th Oct 2017, 7:37 AM
Tamra
Tamra - avatar
+ 14
You can include the <iomanip> file and use the setw() (set width) function to print out a given number of spaces for you. Or, output the string "\t" to print out a tab. Since the equations are different lengths, the columns might be off by a space or two. As to how to calculate two equations at a time, you'll need 2 variables in your first for. It's possible to declare and increment multiple variables at once. for (int x = 1, y = 2; x < 11 && y < 12; x += 2, y += 2) //x is for odd numbers (left column), y is for even numbers (right column) { //Output the two headers here for (int z = 1; z < 10; z++) { //Output equation 1 (x * y) with tabs/spaces if (x*y < 10) cout << " "; //Print 1 extra space for single-digit answers if (z < 10) //Only add this if you don't want to multiply 10's! { //Output equation 2 (z * y) with newline/endl } } }
7th Oct 2017, 9:12 AM
Tamra
Tamra - avatar
+ 1
Thanks a lot, but I want it to be like 1's Multiplication 2's Multiplication 1 x 1 = 1 1 x 2 = 2 //
 //
 is it possible ??
7th Oct 2017, 7:47 AM
Alan Tao
Alan Tao - avatar