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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#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;
}
}
}
}
Last edited on
Topic archived. No new replies allowed.