Functions problem

Hey guys, i recently got this assignment and im just at a total loss where to start (too much work lately, my brain is dying). Here is is the problem:

Write a program that determines which of a company's four divisions (Northeast, Southeast, Northwest, and Southwest) had the greatest sales for a quarter. It should include the following two functions, which are called by main.

* double getSales() is passed the name of a division. It asks the user for a division's quarterly sales figure, validates the input then returns a valid sales figure for that quarter. It should be called once for each division.
* void findHighest() is passed the four sales totals. It determines which is the largest and prints the name of the high grossing division along with its sales figure.

Do not accept dollar amounts less than 0.

I currently have this, but im not sure what to do with it, It's working fine in the sense that its getting the values, but i don't know how to use the getsales () function with the findhighest () function so it finds the highest value. I would appreciate any clue at this point. Sorry for such an open ended question :(

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
#include <cstdlib>
#include <iostream>

using namespace std;

double getsales (double);

int main(int argc, char *argv[])
{
    double northeast = 0;
    double southeast = 0;
    double northwest = 0;
    double southwest = 0;
    
    cout << "Enter NorthEast sales: $" ;
    cout << getsales(northeast) << endl << endl;
    cout << "Enter SouthEast sales: $"; 
    cout << getsales(southeast) << endl << endl;9
    cout << "Enter NorthWest sales: $";
    cout << getsales(northwest) << endl << endl;
    cout << "Enter SouthWest sales: $";
    cout << getsales(southwest) << endl << endl;
    
    system("PAUSE");
    return EXIT_SUCCESS;
}

double getsales (double num)
{
    cin >> num;
    return num;
}
Ok well here's an update, i decided to use reference variable in the getsales function, the program does what its supposed to do, any suggestions? I need to make the findhighest function be able to say the name of the division that got the highest sales, right now its just displaying the highest sales. Any clues on how to do that?
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 <cstdlib>
#include <iostream>

using namespace std;

double getsales (double &);
void findhighest (double, double, double, double);

int main(int argc, char *argv[])
{
    double northeast = 0;
    double southeast = 0;
    double northwest = 0;
    double southwest = 0;
    
    cout << "Enter NorthEast sales: $" ;
    cout << getsales(northeast) << endl;
    cout << "Enter SouthEast sales: $"; 
    cout << getsales(southeast) << endl;
    cout << "Enter NorthWest sales: $";
    cout << getsales(northwest) << endl;
    cout << "Enter SouthWest sales: $";
    cout << getsales(southwest) << endl;
    
    findhighest(northeast, southeast, northwest, southwest);
    
    system("PAUSE");
    return EXIT_SUCCESS;
}

double getsales (double & num)
{
    do
    {
        if(!cin)
        {
            cin.clear();
            cin.ignore(100, '\n');
        }
        
        cin >> num;
        cout << "Number entered: ";
        
        
    }while(!cin || num <= 0);
    return num;
}

void findhighest (double ne, double se, double nw, double sw) 
{
    double high = ne;
    if(se > high)
        high = se;
    if(nw > high)
        high = nw;
    if(sw > high)
        high = sw;
        
    cout << "the highest number is: " << high << endl;
}
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
void findhighest (double ne, double se, double nw, double sw) 
{
    const char *who = "NorthEast";
    double high = ne;
    if(se > high)
    {
        who = "SouthEast";
        high = se;
    }
    if(nw > high)
    {
        who = "NorthWest";
        high = nw;
    }
    if(sw > high)
    {
        who = "SouthWest";
        high = sw;
    }
        
    cout << who << "has the highest sale (" << high << ")" << endl;
}
Topic archived. No new replies allowed.