My code won't compile. HW question

I'm having trouble trying to compile my code. The assignment we are working on is for functions. To use a void function to calculate which division of a company made the most.

When I attempt to compile I get this error message:

[link]
https://scontent.fsnc1-1.fna.fbcdn.net/hphotos-xpt1/v/t34.0-12/12167781_1061831340524370_773486874_n.jpg?oh=8559c4f18b173ed895fe17b74705a665&oe=562730F5
[/link]

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
#include <iostream>
#include <iomanip>
#include <cstdio>
using namespace std;
        
float input_div();
void findHighest (float, float, float, float);
        
 
int main()
{
        float nE, sE, nW, sW;
        int name;
          
        cout << "Northeast Division: " << endl;
        nE = input_div();
        
        cout << "Southeast Division: " << endl;
        sE = input_div();

        cout << "Northwest Division: " << endl;
        nW = input_div();

        cout << "Southwest Division: " << endl;
        sW = input_div();

        findHighest(nE, sE, nW, sW); //prints the result also
        return 0;
}
 
float input_div()
{
float sales;
        do
        {
        cout << "Enter Quarterly sales: $" << endl;
        cin >> sales;
        }
                while (sales > 0.00);
return sales;
}
 
void findHighest ();
{
float highest;
int name;


if (sE > nE && sE > nW && sE > sW)
{
sE = highest;
name = "South East";
}
 
if (nE > nW && nE > sE && nE > sW)
{
nE = highest;
name = "North East";
}
         
if (sW > nE && sW > nW && sW > sE)
{
sW = highest;
name = "South West";
}

if (nW > nE && nW > sW && nW > sE)
{
nW = highest;
name = "North West";
}
 
cout << "The highest is " << name << "with " << highest

}


If you notice anything wrong with my code please let me know. I've been trying to get this guy to run, if you think it'll run improperly please show me how to fix. Thank you!
It appears that you have a stray semicolon at the end of line 43.
The following are the syntax errors I could find.

Since you will deal with strings, you should #include<string>
Take a look at line 43. It should not have a semicolon.
Again at line 43, your function prototype (line 7) does not match the function at line 43. It has not arguments/parameters on line 43, but your prototype has 4 float arguments.
On line 45, you need to initialized the highest variable.
On line 46, you need to change the variable type from int to string. Because, you are using strings in the function findHighest to initialized name (Lines 52,58,64,70).
On line 73, a semicolon is missing.

I hope it helps.

Edited: I forgot, on line 13 int name; is not used anywhere in the main function.
Last edited on
Did you try the link? It listed every error for you.
@chicofeo So I made some updates but I still can't get it to compile. Thank you for the specifity. Here is my updated code and the new errors.

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
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <strings>
using namespace std;
        
float input_div();
void findHighest (float, float, float, float);
 
float nE, sE, nW, sW;
int name;
float highest;
 
int main()
{         
        cout << "Northeast Division: " << endl;
        nE = input_div();
        
        cout << "Southeast Division: " << endl;
        sE = input_div();

        cout << "Northwest Division: " << endl;
        nW = input_div();

        cout << "Southwest Division: " << endl;
        sW = input_div();

        findHighest(nE, sE, nW, sW); //prints the result also
        return 0;
}
 
float input_div();
{
float sales;
        do
        {
        cout << "Enter Quarterly sales: $" << endl;
        cin >> sales;
        }
                while (sales > 0.00);
return sales;
}
 
void findHighest ();
{

if (sE > nE && sE > nW && sE > sW)
{
sE = highest;
name = "South East";
}
 
if (nE > nW && nE > sE && nE > sW)
{
nE = highest;
name = "North East";
}
         
if (sW > nE && sW > nW && sW > sE)
{
sW = highest;
name = "South West";
}

if (nW > nE && nW > sW && nW > sE)
{
nW = highest;
name = "North West";
}
 
cout << "The highest is " << name << "with " << highest;

}


[link]
https://scontent.fsnc1-1.fna.fbcdn.net/hphotos-xpt1/v/t34.0-12/12170714_1062912677082903_1216436916_n.jpg?oh=8af0584a178cc8d88738f474fa17af5e&oe=5627CF84
[/link]
I would avoid using global variables. Nevertheless, I placed a comment in the code below:

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
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <strings> //it should be #include<string> 
using namespace std;
        
float input_div();
void findHighest (float, float, float, float);
 
float nE, sE, nW, sW; // you need to initialized the variables.
int name; // you need to change the variable type from int to string.
          // Because, you are using strings in the function findHighest 
          // to initialized name (Lines 54,60,66,72).           
float highest; // you need to initialized the highest variable.
 
int main()
{         
        cout << "Northeast Division: " << endl;
        nE = input_div();
        
        cout << "Southeast Division: " << endl;
        sE = input_div();

        cout << "Northwest Division: " << endl;
        nW = input_div();

        cout << "Southwest Division: " << endl;
        sW = input_div();

        findHighest(nE, sE, nW, sW); //prints the result also
        return 0;
}
 
float input_div(); //It should not have a semicolon.
{
float sales;
        do
        {
        cout << "Enter Quarterly sales: $" << endl;
        cin >> sales;
        }
        while (sales > 0.00);
return sales;
}
 
void findHighest (); //It should not have a semicolon.
                    // It has not arguments/parameters on line 43, 
		    // but your prototype (line 8) has 4 float arguments.
{

if (sE > nE && sE > nW && sE > sW)
{
sE = highest;
name = "South East";
}
 
if (nE > nW && nE > sE && nE > sW)
{
nE = highest; 
name = "North East";
}
         
if (sW > nE && sW > nW && sW > sE)
{
sW = highest;
name = "South West";
}

if (nW > nE && nW > sW && nW > sE)
{
nW = highest;
name = "North West;
}
 
cout << "The highest is " << name << "with " << highest;

} 
Last edited on
Topic archived. No new replies allowed.