hey guys im learning if loops online in a class and my teacher wants us to modify this table he has given us slightly to make it where its a multiplication table and it goes all the way up to 9 times 9 and ive tried it but my code comes out bad, i love this and ive been playing around with it and still nothing. he also wants the zeros removed in the column and rows too which im trying to do but i cant! its making me mad heres the code i have so far. what im i doing wrong?
#include <iostream>
using namespace std;
int main()
{
for (int row = 0; row < 9*3; row++)
{
for (int col = 0; col < 9*3; col++)
{
cout << row * col << "\t";
}
cout << endl;
Your teacher is a joker. ;-) You don't have to 'remove' the zeros. Here is an example:
1 2 3 4
for (size_t i{ 1 }; i <= 9; ++i)
{
// Do some work here ...
}
Here is a working example with basic output that demonstrates this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include <iomanip>
#include <iostream>
auto main() -> int
{
const size_t multiplier{ 9 };
for (size_t i{ 1 }; i <= multiplier; ++i)
{
std::cout << std::setw(3) << i << " |";
for (size_t j{ 1 }; j <= multiplier; ++j)
{
std::cout << " " << std::setw(3) << (i * j) << " |";
}
std::cout << std::endl;
}
return 0;
}
To have a nicely formatted output, you would have to add two additional loops BEFORE the one in my example, the second one's variable being initialized to 0, and one AFTER the main loop, to achieve the following look: