Hello, everyone. I am in a c++ class and I have to create a multiplication table for an assignment. We have to use <iomanip> to format the cells so that they line up. My first problem, I have to make the "Mult table" on the same row as the horizontal numbers being displayed and I didn't know how to make a for loop for that. My second problem, I am not sure how to multiple the numbers together. I should end up with something similar to this if I entered:
for(bstart=0;bstart<ncol;bstart++)
{
cout << setw(3+p) << "b=" << bstart << " "; // Removed the spaces to match your illustration
}
cout << endl;
for(astart=0;astart<nrows;astart++) // Your original loop
{
cout << setw(9) << "a=" << astart; // Again, removed the spaces before and after the =
for(bstart=0;bstart<ncol;bstart++)
{
cout << setw(4+p) << astart*bstart << " "; // Multiplies the two numbers
}
cout << endl; // Newline, of course
}
But..
You are not using the user's inputs. You're starting the loops with a zero, and going up to base value.
To use their inputs, use this section, instead.
@whitenite1 The second code is what I wanted! Thank you! But I am confused why the "a" values are incrementing by 10 digits every pass. The b columns are perfect but i cant figure out how to fix the a rows.
Could you explain a bit better? Everything looks correct for me. The a table will start with what you input as start value for base a, and continue for how many base values you requested. So, if you input 8 for base a, and 6 for base values, a will print out from 8 to 13, and those will multiply with whatever number you inputted for base b.
@whitenite1 I apologize, I was tweaking your code a little bit to do what my program specifically said and I accidentally typed "a+10" and it didn't do what I wanted it to do. But thank you for the code. My program now works perfectly!!