Even sum of of multiplication table?

Hello all, first time poster, long time reader. Anyway, i'm at my wits end with this week's assignment.

This assignment creates a multiplication table, then adds the even and odd numbers in the table together and outputs them. The first for statement(which creates the multiplication table) works perfectly with no problems.

The hard part now lies in the fact that I also must add all even and odd numbers within the multiplication table, which i cannot figure out. The following is my code(ignore my attempts at humor).

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
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

int main()
{
	int num;
	int rows;
	int columns;
	double oddSum = 0;
	double evenSum = 0;
	double ratio;

	cout << " Welcome to the Handy Dandy Multiplication table!" << endl << endl;
	cout << " This program allows you to create a personal multiplication table" <<  endl;
	cout << " Which assists you in the addition of even and odd numbers, as well as the ratio of the two" << endl;
	cout << " How many rows of multiples would you like?(Horizontal rows)" << endl;
	cin >> num;
	cout << endl;
	cout << " Here is your handy dandy multiplication table" << endl;
	cout << " Composed of " << num << " Horizontal rows" << endl << endl;

	for(rows = 1; rows <= num; rows++)
	{
		for(columns = 1; columns <= 15; columns++)
			
			cout << setw(5) << rows * columns;
			cout << endl << endl;
	}

	
		
	if(rows * columns % 2 == 0)
	{
			evenSum = evenSum + (columns * rows);
			cout << " Even sum is equal to: " << evenSum << endl;
	
        /* This if statement does not accurately add up the even numbers in the table*/

        }

	

	

	system("PAUSE");
	return 0;
}



Any tips?
Last edited on
Hello, your statement for working out the even sum isn't incorrect. Just think about where you are placing it.
place the if(rows * columns % 2 == 0) statement in the body of the
for(columns = 1; columns <= 15; columns++) loop.
Topic archived. No new replies allowed.