Table of subtraction

I am trying to create a subtraction table where you subtract the number of column from the number of row, and the answer appears within the table. For example if it is the 3rd row down, and the 2nd column over, then the answer is 1

Something like this: http://www.mathatube.com/images/times-_and_division_table_chart-7.gif , except I only need mine to go to display 4 rows and 5 columns.

Currently it seems to format wrong, Can anyone help me?
here is my code


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
58
59
60

# include <iostream>
# include <iomanip>
using namespace std;

//Function size-Tells user to enter number of rows and columns.
void size (int&row, int&column) {
	
	cout<<"Enter number of rows:";
	cin>> row;
	
	while (row < 1 || row > 12) {
		cout<<"Invalid number."<<endl;
		cout<<"Enter number of rows:";
		cin>> row; 
	}
	cout<<"Enter number of columns:";
	cin>> column;
	
	while (column < 1 || column > 9) {
		cout<<"Invalid number."<<endl;
		cout<<"Enter number of columns:";
		cin>> column; 
	}
}
//Function subtraction-Subtracts b from a
int subtraction (int a, int b) {
	
	int diff;
	diff = a - b;
	
	return diff;
}
//Function show--displays the bars needed to create a table
void show ( ) {
	int answer;

	
	cout<< "___________________"<< endl;
	
	for (int a=1; a<=5; a++) {
	
		
		for (int b=1; b<=4; b++) {
			
			answer = subtraction(a,b);
			cout << subtraction(a,b);
		}
		cout<< a << "|" << answer <<endl;
	}
}
//Main function-calls other functions. 
int main ( ){
	int row, column;
	
	size(row, column);
	show( );

	return 0;
}
I think I'm misusing a global variable somewhere? but I don't know what specifically.
i dont know wat are u trying to do..
and u dont even use any global variable..
u ask the value of row and column from function size..
but then u use of it nowhere..
even in show or substract u're not using that variable
may be this is ur problem

void show ()
{
int answer;

cout<< "___________________"<< endl;

for (int a=1; a<=5; a++) {


for (int b=1; b<=4; b++) {

answer = subtraction(a,b);
cout << subtraction(a,b);
}
cout<< a << "|" << answer <<endl;
}
}

u're substract 2 time..
first u substract and put the value into answer..
then u subtract again and cout the value..

may be u should change to


answer = subtraction(a,b);
cout << answer;

or just use

cout << subtraction(a,b);
Topic archived. No new replies allowed.