Need help with using multiple functions

Hello, this is my first time posting and I am desperate for assistance. I've exhausted all my resources, and a forum is all I could think to turn to.

I have been taking a C++ intro course over the past month, and I am having issues understanding how to overcome and solve our weekly program assignment.

Just for context, the question basically asks this:


Write a program that determines which of the four districts (northEast, northWest, southEast, southWest) made the most money this month.
It specifies to pass the name of the district to "double getSales()" and also have it ask for the sales figure, validate it (make sure the number is not zero or negative), and return it to the "main" function.
It then specifies to pass the four values to "void findHighest()" and use it to determine which district made the most. And then display it, of course.


Because I have never used anything other than "int main()," I initially wrote the program with while loops to validate the entered in values (with "cin") and then used "if/else if" with four inequality expressions to determine the highest number. The program worked perfectly.

NOW onto my confusion. I have no idea how to pass a variable from "int main" to another function. I know how to do integers, but how I could pass the name of a district to "double getSales()" is beyond my knowledge AND every program example in my 87 page-long chapter. ALSO, I thought I did the "void" expression correctly (well, what I mean is it runs), but whenever I execute the code, the "northWest" division is ALWAYS the highest value, which makes no sense if "southWest" is a higher value.


So my questions are these:

With the code below for reference, what is exactly wrong with my void function? (I removed the "double getSales()" completely because I cannot get the program to run when I try to implement it, and I substituted it with my original while loops for the time being.)

What would be a plausible route to take in order to implement "double getSales()?"

Thanks in advance for any assistance or advice!


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
#include <iostream>
#include <iomanip>
using namespace std;

void findHighest(double, double, double, double);
int main()
{
        double northEast, northWest, southEast, southWest;

        cout << "What is the quarterly sales figure for NE?\n";
	cin >> northEast;
	while (northEast <= 0)
	{
		cout << "The number you inputted is invalid. Please try again and use only positive numbers.";
		cin >> northEast;
	}


	cout << "What is the quarterly sales figure for NW?\n";
	cin >> northWest;
	while (northWest <= 0)
	{
		cout << "The number you inputted is invalid. Please try again and use only positive numbers.";
		cin >> northWest;
	}


	cout << "What is the quarterly sales figure for SE?\n";
	cin >> southEast;
	while (southEast <= 0)
	{
		cout << "The number you inputted is invalid. Please try again and use only positive numbers.";
		cin >> southEast;
	}


	cout << "What is the quarterly sales figure for SW?\n";
	cin >> southWest;
	while (southWest <= 0)
	{
		cout << "The number you inputted is invalid. Please try again and use only positive numbers.";
		cin >> southWest;
	}



	findHighest(northEast, northWest, southEast, southWest);

	system("pause");
	return 0;
}


void findHighest(double northEast, double northWest, double southEast, double southWest)
{
	if (northEast > northWest && northEast > southEast && northEast > southWest)
		cout << "Northeast division is the highest grossing for this quarter, \nwith a total of $" << northEast << ".\n";

	else if (northWest > northEast && northWest > southEast && northWest > southWest)
		cout << "Northwest division is the highest grossing for this quarter, \nwith a total of $" << northWest << ".\n";

	else if (southEast > northWest && southEast > northEast && southEast > southWest)
		cout << "Southeast division is the highest grossing for this quarter, \nwith a total of $" << southEast << ".\n";

	else if (southWest > northWest && southWest > northEast && southWest > southEast)
		cout << "Southwest division is the highest grossing for this quarter, \nwith a total of $" << southWest << ".\n";
}
Last edited on
UPDATE: I just caught an issue in my code for the void function. '&&' can only connect two expressions, and I had to restate the district variable being compared to the other three districts for each inequality in each if/else if statement.

I have edited my program and also updated it in the above code.

However, that is honestly the extent of my knowledge, and I have ZERO idea what to do for the "double getSales()."
Last edited on
Topic archived. No new replies allowed.