Sales informations

Hello,
I'm trying to figure why all of the sudden my program isn't running correctly. It was running just fine. Now when I run it, it will ask for the values, but stop at east quarter1 and I cant figure out why. Any advise would be very appreciated.

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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

char again; 
const int COLS = 5;
const int ROWS = 5;

void showArray(int[][COLS], int);
int getTotal(int [][COLS]);
double getAverage(int[][COLS]);
int getRowTotal(int[ROWS][COLS], int);
int getColumnTotal(int[ROWS][COLS], int);
int getHighest(int[][COLS], int&);
int getLowest(int[][COLS], int&);

int main()
{
    int a = 1;
	static int a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20;
	static int a21, a22, a23, a24, a25;
	cout << "North Quarter1 sales: ";
	cin >> a1;
	cout << "North Quarter2 sales: ";
	cin >> a2;
	cout << "North Quarter3 sales: ";
	cin >> a3;
	cout << "North Quarter4 sales: ";
	cin >> a4;
	cout << "South Quarter1 sales: ";
	cin >> a5;
	cout << "South Quarter2 sales: ";
	cin >> a6;
	cout << "South Quarter3 sales: ";
	cin >> a7;
	cout << "South Quarter4 sales: ";
	cin >> a8;
	cout << "East Quarter1 sales: ";
	cin >> a9;
	cout << "East Quarter2 sales: ";
	cin >> a10;
	cout << "East Quarter3 sales: ";
	cin >> a11;
	cout << "East Quarter4 sales: ";
	cin >> a12;
	cout << "West Quarter1 sales: ";
	cin >> a13;
	cout << "West Quarter2 sales: ";
	cin >> a14;
	cout << "West Quarter3 sales: ";
	cin >> a15;
	cout << "West Quarter4 sales: ";
	cin >> a16;
	cout << endl;
	
	a17 = a1 + a2 + a3 + a4;
	a18 = a5 + a6 + a7 + a8;
	a19 = a9 + a10 + a11 + a12;
	a20 = a13 + a14 + a15 + a16;
	a21 = a1 + a5 + a9 + a13;
	a22 = a2 + a6 + a10 + a14;
	a23 = a3 + a7 + a11 + a15;
	a24 = a4 + a8 + a12 + a16;
	a25 = a17 + a18 + a19 + a20;
	int table[ROWS][COLS] = {{a1, a2, a3, a4, a17}, {a5, a6, a7, a8, a18}, {a9, a10, a11, a12, a19}, {a13, a14, a15, a16, a20}, {a21, a22, a23, a24, a25}};
    int total = 0;
    double average = 0;
    int rowTotal = 0;
    int columnTotal = 0;
    int highestRow = 0;
    int lowestRow = 0;
	int lowest, highest;
        
	total = getTotal(table);
    average = getAverage(table);
    rowTotal = getRowTotal(table, a);
    columnTotal = getColumnTotal(table, a);
    highestRow = getHighest(table, a);
    lowestRow = getLowest(table, a);
        
	
	cout << "  Q1   Q2   Q3   Q4   DT\n";
	showArray(table, ROWS); 
    cout << endl << "The total is: " << total << endl;
    cout << "The average is: " << average << endl;
    cout << "The total of South division is: " << rowTotal << endl;
    cout << "The total of Quarter 2 is: " << columnTotal << endl;
    cout << "The highest amount in the South division is: " << highestRow << endl;
    cout << "The lowest amount in South division is: " << lowestRow << endl << endl;
    system("pause");
	return 0;
}
void showArray(int array[][COLS], int rows)
{
    for (int x = 0; x < rows; x++)
    {
        for (int y = 0; y < COLS; y++)
        {
            cout << setw(4) << array[x][y] << " ";
        }
        cout << endl;
    }
}
int getTotal(int array[][COLS])
{
    int total = 0;
    for(int x = 0; x < ROWS; x++)
    {
        for(int y = 0; y < COLS; y++)
        {
            total += array[x][y];
        }
    }
    return total;
}
double getAverage(int array[][COLS])
{
    double total = getTotal(array);
    return total / (ROWS * COLS);
}
int getRowTotal(int array[ROWS][COLS], int a)
{
    int sum = 0;
    for(int i = 0; i < COLS; i++)
    {
        sum += array[a][i];
    }
    return sum;
}
int getColumnTotal(int array[ROWS][COLS], int a)
{
    int sum = 0;
    for(int i = 0; i < ROWS; i++)
    {
        sum += array[i][a];
    }
    return sum;
}
int getHighest(int array[][COLS], int& a)
{
	int highest = 0;
    highest = array[a][0];
    for(int i = 1; i < COLS; i++)
    {
        if(array[a][i] > highest)
        {
            highest = array[a][i];
        }
    }
     return highest;
}
int getLowest(int array[][COLS], int& a)
{
	int lowest = 0;
    lowest = array[a][0];
     for(int i = 1; i < COLS; i++)
    {
        if(array[a][i] < lowest)
        {
            lowest = array[a][i];
        }
    }
    return lowest;
}
I ran the code through this site (see the button at the top right of the code box) and it prompted me for all the info.

Some of the reporting seems to be off though. I put in 5 for all the sales figures.

North Quarter1 sales: 5
North Quarter2 sales: 5
North Quarter3 sales: 5
North Quarter4 sales: 5
South Quarter1 sales: 5
South Quarter2 sales: 5
South Quarter3 sales: 5
South Quarter4 sales: 5
East Quarter1 sales: 5
East Quarter2 sales: 5
East Quarter3 sales: 5
East Quarter4 sales: 5
West Quarter1 sales: 5
West Quarter2 sales: 5
West Quarter3 sales: 5
West Quarter4 sales: 5

  Q1   Q2   Q3   Q4   DT
   5    5    5    5   20 
   5    5    5    5   20 
   5    5    5    5   20 
   5    5    5    5   20 
  20   20   20   20   80 

The total is: 320
The average is: 12.8
The total of South division is: 40
The total of Quarter 2 is: 40
The highest amount in the South division is: 20
The lowest amount in South division is: 5



You could have the data input directly into the array instead of creating all those separate variables.

Tested under Visual Studio 2013 Ultimate and works as Wildblue's output.
Topic archived. No new replies allowed.