some problem about division

Hi,
I am confusing with the problem about duplicate top divisions. If the output of the North East and South East are the same, what can I do in the code?

Thank you

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
#include <iostream>
#include <string>
using namespace std;
float input_div(string);
void findHighRev(float, float, float, float);
int stop;
float entry;
int main()
{
        float nE, sE, nW, sW;

        nE = input_div( "North East" );         
        sE = input_div( "South East" );         
        nW = input_div( "North West" );         
        sW = input_div( "South West" );         

        findHighRev(nE, sE, nW, sW);  
        return 0;
}



float input_div(string name)
{
float entry;
entry = -1;
  
  
while (entry < 0){    
  cout <<"Enter a positive number\n";
     cout << "Enter the sales for " << name << " division: $";
   cin >> entry;}



     return entry;
}


void findHighRev (float nE, float sE, float nW, float sW)
{

  string name;
  float highest;
  highest = nE;
  name = "North East";

        if(sE > highest)
      {
                highest = sE;
                name = "South East";
      }

        if(nW > highest)
      {
                highest = nW;
                name = "North West";
      }

        if(sW > highest)
      {
                highest = sW;
                name = "South West";
      }

        cout << "the highest is " << name << " with" << highest << "\n\n";
        cin >> stop;
} 
you can print both, or you can print whichever you want. what do you want the program to do? Before you can code it, you have to know what you want to do.

one way to fix it here is if nW == highest name+= " and North West" else if(nW>highest) //as before.

if you do it right it will work; if the highest are multiple it will append them and if something new is bigger, it discards and starts over with an assignment.
Last edited on
Topic archived. No new replies allowed.