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:
#include <iostream>
#include <iomanip>
#include <cstdio>
usingnamespace 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!
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.
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <strings> //it should be #include<string>
usingnamespace 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;
}