Debugging Help

I'm a newbie at C++ and haven't had any problem up until now, but the assignment is to find the 3 logical errors and I think I've narrowed down where the problem is but I'm at a lost how to fix it as I'm not seeing the problem. Plus I think I'm making it worst as the console is starting to freeze my computer when I try debugging it. Any help will be greatly 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

// Monthly Sales Analysis

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

// Function Prototypes
void inputData(double[]);
int lowMonth(double[]);
int highMonth(double[]);
double averageSales(double[]);

const char * monthArray[] = {"January", "February", "March", "April",
                        "May", "June", "July", "August",
                        "September", "October", "November", "December"};
const int NUM_MONTHS = 12;

int main()
{
	double salesArray[NUM_MONTHS];
	int low, high;
	double average;

	// Input the monthly sales data
	inputData(salesArray);

	// Find the month with the highest sales
	high = highMonth(salesArray);

	// Find the month with the lowest sales
	low = lowMonth(salesArray);

	// Calculate the average monthly sales
	average = averageSales(salesArray);

    // Display results
	cout << "The highest sales were in " << monthArray[high] << " with $" << setprecision(2) << fixed << salesArray[high] << endl;
	cout << "The lowest sales were in " << monthArray[low] << " with $" << setprecision(2) << fixed << salesArray[low] << endl;
	cout << "The average monthly sales were $" << setprecision(2) << fixed << average << endl; 
	//cin.get();
	//cin.get();
}

// This functions requests the monthly sales data from the user
void inputData(double sales[])
{
	for (int i = 0; i < NUM_MONTHS; i++)
	{
		cout << "Please enter the sales in dollars for " << monthArray[i] << " ";
		cin >> sales[NUM_MONTHS];
	}
	return;
}

// This function determines which month had the highest sales and 
// returns the number for that month, 0 = January, 1 = February, etc.
int highMonth(double sales[])
{
	double highest;
	highest = sales[i];

	for (int i = 0; i < NUM_MONTHS; i++)
	{
		if (sales[i] > highest)
		{
			highest = sales[i];
			highest = i;
		}
	}
	return highest;
}

// This function determines which month had the lowest sales and 
// returns the number for that month, 0 = January, 1 = February, etc.
int lowMonth(double sales[])
{
	double lowest;
	lowest = sales[0];

	for (int i = 0; i < NUM_MONTHS; i++)
	{
		if (sales[i] < lowest)
		{
			lowest = sales[i];
			lowest = i;
		}
	}
	return lowest;
}

// This function computes the average monthly sales
double averageSales(double sales[])
{
	double sum = 0;

	for (int i = 1; i < NUM_MONTHS; i++)
	{
		sum += sales[i];
	}
	return sum / NUM_MONTHS;
}


Here is one of them:
1
2
3
4
5
6
7
8
9
10
// This functions requests the monthly sales data from the user
void inputData(double sales[])
{
	for (int i = 0; i < NUM_MONTHS; i++)
	{
		cout << "Please enter the sales in dollars for " << monthArray[i] << " ";
		cin >> sales[NUM_MONTHS];  //<<<<< *****************
	}
	return;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int highMonth(double sales[])
{
	double highest;
	highest = sales[i]; //<<<<<<<<<<<<

	for (int i = 0; i < NUM_MONTHS; i++)
	{
		if (sales[i] > highest)
		{
			highest = sales[i];
			highest = i;
		}
	}
	return highest;
}


Can a variable be used if its not yet declared? :)
Topic archived. No new replies allowed.