Not displaying greatest number?

Need some help with debugging why my code isn't correctly choosing the division with the highest sales figure? Thanks guys!

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
//Finds the highest sales figure of a company's 4 divisions
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;

//function prototype
double getSales(string);
void findHighest(double, double, double, double);

int main ()
{
	double NEsales, SEsales, NWsales, SWsales;
	string division;

	division = "Northeast";
	NEsales = getSales(division);
	
	division = "Southeast";
	SEsales = getSales(division);
	
	division = "Northwest";
	NWsales = getSales(division);
	
	division = "Southwest";
	SWsales = getSales(division);

	findHighest(NEsales, SEsales, NWsales, SWsales);

	system("pause");
	return 0;
}

double getSales(string division)
{
	double sales;
	cout << "Please enter the sales figure for The " << division << " Division." << endl;
	cout << "Sales Figure: $";
	cin >> sales;
	
	while (sales < 0.00)
	{
		cout << "\nInvalid Request. Sales must be greater than $0.00" << endl;
		cin.clear();
		cin.ignore();
		cin >> sales;
	}
	return sales;
}

void findHighest(double NE, double SE, double NW, double SW)
{
	if (NE > SE && NW && SW)
	{
		cout << "\nHighest Grossing Division: Northeast Division" << endl;
		cout << "Sales Figure: $" << fixed << setprecision(2) << NE << endl;
	}

	else if (SE > NE && NW && SW)
	{
		cout << "\nHighest Grossing Division: Southeast Division" << endl;
		cout << "Sales Figure: $" << fixed << setprecision(2) << SE << endl;
	}

	else if (NW > NE && SE && SW)
	{
		cout << "\nHighest Grossing Division: Northwest Division" << endl;
		cout << "Sales Figure: $" << fixed << setprecision(2) << NW << endl;
	}

	else if (SW > NE && NW && SE)
	{
		cout << "\nHighest Grossing Division: Southwest Division" << endl;
		cout << "Sales Figure: $" << fixed << setprecision(2) << SW << endl;
	}
}
closed account (48T7M4Gy)
my code isn't correctly choosing the division with the highest sales figure
Perhaps you might like to give a little more detail than that.

The usual way to describe a problem is to say what you input, what you got as output and why that isn't what you expect. Often an indication of what testing you have done is a good move and perhaps even your thoughts on where the problem might be. Remember, it's unlikely anyone has seen your code before and even less likely to know what it is supposed to do. It's in your interests to provide the few extra lines of explanation.
kemort,

Ok, here is what I mean. I'll give an example.
If I input $345 for Northeast, $32 for Southeast, $46 for Northwest, and $753 for Southwest. The function findHighest(), displays Northeast Division with having the highest sales figure with $345. Obviously this isn't correct. I went wrong somewhere with my if and else if statements in that particular function. I've been trying and trying to see where I went wrong. But I keep getting similar wrong calculations each time.

Thanks
Nevermind, I got it figured out on my own eventually. I was doing the if statements' conditions wrong. Here is the final product.

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
//Finds the highest sales figure of a company's 4 divisions
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;

//function prototype
double getSales(string);
void findHighest(double, double, double, double);

int main ()
{
	double NEsales, SEsales, NWsales, SWsales;
	string division;

	division = "Northeast";
	NEsales = getSales(division);
	
	division = "Southeast";
	SEsales = getSales(division);
	
	division = "Northwest";
	NWsales = getSales(division);
	
	division = "Southwest";
	SWsales = getSales(division);

	findHighest(NEsales, SEsales, NWsales, SWsales);

	system("pause");
	return 0;
}

double getSales(string division)
{
	double sales;
	cout << "Please enter the sales figure for The " << division << " Division." << endl;
	cout << "Sales Figure: $";
	cin >> sales;
	
	while (sales < 0.00)
	{
		cout << "\nInvalid Request. Sales must be greater than $0.00" << endl;
		cin.clear();
		cin.ignore();
		cin >> sales;
	}
	return sales;
}

void findHighest(double NE, double SE, double NW, double SW)
{
	if (NE > SE && NE > NW && NE > SW)
	{
		cout << "\nHighest Grossing Division: Northeast Division" << endl;
		cout << "Sales Figure: $" << fixed << setprecision(2) << NE << endl;
	}

	else if (SE > NE && SE > NW && SE > SW)
	{
		cout << "\nHighest Grossing Division: Southeast Division" << endl;
		cout << "Sales Figure: $" << fixed << setprecision(2) << SE << endl;
	}

	else if (NW > NE && NW > SE && NW > SW)
	{
		cout << "\nHighest Grossing Division: Northwest Division" << endl;
		cout << "Sales Figure: $" << fixed << setprecision(2) << NW << endl;
	}

	else
	{
		cout << "\nHighest Grossing Division: Southwest Division" << endl;
		cout << "Sales Figure: $" << fixed << setprecision(2) << SW << endl;
	}
}
closed account (48T7M4Gy)
Well done, MisterTams, I'm glad you were able to solve it.

Depending where you are with your C++ studies this problem lends itself to arrays which reduce the amount of duplication and make life a lot easier in finding the highest value. :)
Topic archived. No new replies allowed.