### i am trying to write a multiplication table and something is wrong

#include <iostream>

using namespace std;

int main()
{
int i;
int j;
char ch;

for (i = 1; i <= 5; i++)
{
for (j =1; j<=5; j++)
{
if ( i == 1 && j <= i)
{
cout << i << "x" << j << "=" << i * j << "\n";
cout << endl;
}

else if ( i == 2 && j <= i)
{
if (j == 2)
cout << i << "x" << j << "=" << i * j << "\t" << endl;
else
cout << i << "x" << j << "=" << i * j << "\t";
}

else if ( i == 3 && j <= i)
{
if (j == 3)
cout << i << "x" << j << "=" << i * j << "\t" << endl;
else
cout << i << "x" << j << "=" << i * j << "\t";
}

else if ( i == 4 && j <= i)
{
if (j == 4)
cout << i << "x" << j << "=" << i * j << "\t" << endl;
else
cout << i << "x" << j << "=" << i * j << "\t";
}

else if ( i == 5 && j <= i)
{
if (j == 5)
cout << i << "x" << j << "=" << i * j << "\t" << endl;
else
cout << i << "x" << j << "=" << i * j << "\t";
cin >> ch;
return 0;
}

This is what I want it to look like:
1x1= 1
2x1= 2 2x2=4
3x1= 3 3x2=6 3x3=9
4x1= 4 4x2=8 4x3=12 4x4=16
5x1= 5 5x2=10 5x3=15 5x4=20 5x5=25

You simply did not close off your curly braces at the bottom.

 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 #include using namespace std; int main() { int i; int j; char ch; for (i = 1; i <= 5; i++) { for (j =1; j<=5; j++) { if ( i == 1 && j <= i) { cout << i << "x" << j << "=" << i * j << "\n"; cout << endl; } else if ( i == 2 && j <= i) { if (j == 2) cout << i << "x" << j << "=" << i * j << "\t" << endl; else cout << i << "x" << j << "=" << i * j << "\t"; } else if ( i == 3 && j <= i) { if (j == 3) cout << i << "x" << j << "=" << i * j << "\t" << endl; else cout << i << "x" << j << "=" << i * j << "\t"; } else if ( i == 4 && j <= i) { if (j == 4) cout << i << "x" << j << "=" << i * j << "\t" << endl; else cout << i << "x" << j << "=" << i * j << "\t"; } else if ( i == 5 && j <= i) { if (j == 5) cout << i << "x" << j << "=" << i * j << "\t" << endl; else cout << i << "x" << j << "=" << i * j << "\t"; cin >> ch; return 0; } } } }
Last edited on
Topic archived. No new replies allowed.