Member Avatar for Nick6425fl

I can't get it to compile.

Here are the instructions for the assignment:

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 divi-
sion’s quarterly sales figure, validates the input, then returns it. 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.
Input Validation: Do not accept dollar amounts less than $0.00.
I'm not looking for anyone to do my homework...just help if you can. Thank you for looking.

#include <iostream>
#include <iomanip>
#include <cstring> 
 
using namespace std;



const int NAME_SIZE = 26;


double getSales (char []);
void findHighest(double, double, double, double);

int main()
{

double input_div(string);
   double salesNE,  
          salesSE,  
          salesNW,  
          salesSW; 

   
   salesNE = getSales("Northeast"); 
   salesSE = getSales("Southeast"); 
   salesNW = getSales("Northwest"); 
   salesSW = getSales("Southwest"); 


   findHighest( salesNE, salesSE, salesNW, salesSW);
  

cout << "Enter the quarterly sales for the Northeast division: ";
cin >> salesNE;

while (salesNE <=0)
{
cout << "Sales must be a non-negative number.";
cout << "Enter the quarterly sales for the Northeast division: ";
cin >> salesNE;

}
cout << "Enter the quarterly sales for the Southeast division: ";
cin >> salesSE;
while (salesSE <=0)
{
cout << "Sales must be a non-negative number.";
cout << "Enter the quarterly sales for the Southeast division: ";
cin >> salesSE;
}

cout << "Enter the quarterly sales for the Northwest division: ";
cin >> salesNW;
while (salesNW <=0)
{
cout << "Sales must be a non-negative number.";
cout << "Enter the quarterly sales for the Northwest division: ";
cin >> salesNW;
}
cout << "Enter the quarterly sales for the Southwest division: ";
cin >> salesSW;
while (salesSW <=0)
{
cout << "Sales must be a non-negative number.";
cout << "Enter the quarterly sales for the Southwest division: ";
cin >> salesSW;

}
}
void findHighest(double salesNE, double salesSE, double salesNW, double salesSW)
{
  string highest, name;
  highest = "salesNE";
  name = "Northeast";

	if(salesSE > highest)
      {
         highest = "salesSE";
	     name = "Southeast";
      }

	if(salesNW > highest)
      {
		highest = "salesNW";
		name = "Northwest";
      }

	if(salesSW > highest)
      {
		highest = "salesSW";
		name = "Southwest";
      }

	cout << "The highest division is " << name << " with $" << highest << endl;
}

 return 0;
}
Member Avatar for Nick6425fl
#include <iostream>
#include <iomanip>
#include <cstring> 
 
using namespace std;



const int NAME_SIZE = 26;


double getSales (char []);
void findHighest(double, double, double, double);

int main()
{

double input_div(string);
   double salesNE,  
          salesSE,  
          salesNW,  
          salesSW; 

   
   salesNE = getSales("Northeast"); 
   salesSE = getSales("Southeast"); 
   salesNW = getSales("Northwest"); 
   salesSW = getSales("Southwest"); 


   findHighest( salesNE, salesSE, salesNW, salesSW);
  

cout << "Enter the quarterly sales for the Northeast division: ";
cin >> salesNE;

while (salesNE <=0)
{
cout << "Sales must be a non-negative number.";
cout << "Enter the quarterly sales for the Northeast division: ";
cin >> salesNE;

}
cout << "Enter the quarterly sales for the Southeast division: ";
cin >> salesSE;
while (salesSE <=0)
{
cout << "Sales must be a non-negative number.";
cout << "Enter the quarterly sales for the Southeast division: ";
cin >> salesSE;
}

cout << "Enter the quarterly sales for the Northwest division: ";
cin >> salesNW;
while (salesNW <=0)
{
cout << "Sales must be a non-negative number.";
cout << "Enter the quarterly sales for the Northwest division: ";
cin >> salesNW;
}
cout << "Enter the quarterly sales for the Southwest division: ";
cin >> salesSW;
while (salesSW <=0)
{
cout << "Sales must be a non-negative number.";
cout << "Enter the quarterly sales for the Southwest division: ";
cin >> salesSW;

}
}
void findHighest(double salesNE, double salesSE, double salesNW, double salesSW)
{
  string highest, name;
  highest = "salesNE";
  name = "Northeast";

	if(salesSE > highest)
      {
         highest = "salesSE";
	     name = "Southeast";
      }

	if(salesNW > highest)
      {
		highest = "salesNW";
		name = "Northwest";
      }

	if(salesSW > highest)
      {
		highest = "salesSW";
		name = "Southwest";
      }

	cout << "The highest division is " << name << " with $" << highest << endl;
}

 return 0;
}

As to the error, lines like this are illegal, where highest is defined as a string and salesSE is a double:

if(salesSE > highest)

You can compare two strings and you can compare two integers, but you can't compare an integer and a string like that. You should be comparing doubles to doubles in the if statement in this case. There are a variety of ways to find the maximum of four doubles, but before you do that, decide exactly what you are supposed to be returning:

void findHighest(double salesNE, double salesSE, double salesNW, double salesSW)

Why is is this a void function? Are you sure it's not supposed to return a double? It appears that it SHOULD be a void from below.

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.
Input Validation: Do not accept dollar amounts less than $0.00.

The assignment specification has a problem in it. It says in words that the function is "passed" four parameters, but the specification above takes no parameters.

You are probably supposed to do something like:

if (salesSE >= salesNE && salesSE >= salesNW && salesSE >= salesSW)
{
     // display that southeast has highest sales, display sales amount
     return;
}
Member Avatar for Nick6425fl

Ok that makes so much sense...thank you. I changed the code to find the highest, but when I try to end the code with return 0; it give me an error about returning to a void statement. when i try to end with getchar(); it says--- undefined reference to `getSales(char*)'

code updated

#include <iostream>
#include <iomanip>
#include <cstring> 
 
using namespace std;



const int NAME_SIZE = 26;


double getSales (char []);
void findHighest(double, double, double, double);

int main()
{

double input_div(string);
   double salesNE,  
          salesSE,  
          salesNW,  
          salesSW; 

   
   salesNE = getSales("Northeast"); 
   salesSE = getSales("Southeast"); 
   salesNW = getSales("Northwest"); 
   salesSW = getSales("Southwest"); 


   findHighest( salesNE, salesSE, salesNW, salesSW);
  

cout << "Enter the quarterly sales for the Northeast division: ";
cin >> salesNE;

while (salesNE <=0)
{
cout << "Sales must be a non-negative number.";
cout << "Enter the quarterly sales for the Northeast division: ";
cin >> salesNE;

}
cout << "Enter the quarterly sales for the Southeast division: ";
cin >> salesSE;
while (salesSE <=0)
{
cout << "Sales must be a non-negative number.";
cout << "Enter the quarterly sales for the Southeast division: ";
cin >> salesSE;
}

cout << "Enter the quarterly sales for the Northwest division: ";
cin >> salesNW;
while (salesNW <=0)
{
cout << "Sales must be a non-negative number.";
cout << "Enter the quarterly sales for the Northwest division: ";
cin >> salesNW;
}
cout << "Enter the quarterly sales for the Southwest division: ";
cin >> salesSW;
while (salesSW <=0)
{
cout << "Sales must be a non-negative number.";
cout << "Enter the quarterly sales for the Southwest division: ";
cin >> salesSW;

}
}
void findHighest(double salesNE, double salesSE, double salesNW, double salesSW)

{
 if (salesSE >= salesNE && salesSE >= salesNW && salesSE >= salesSW)
{
     cout << "The highest division is the Southeast division\
     with $" << salesSE << endl;
     return;
}

if (salesNE >= salesSE && salesNE >= salesNW && salesNE >= salesSW)
{
     cout << "The highest division is the Northeast division\
     with $" << salesNE << endl;
     return;
}
if (salesSW >= salesNE && salesSW >= salesNW && salesSW >= salesSE)
{
     cout << "The highest division is the Southwest division\
     with $" << salesSW << endl;
     return;
}
 if (salesNW >= salesNE && salesNW >= salesSE && salesNW >= salesSW)
{
     cout << "The highest division is the Southeast division\
     with $" << salesSE << endl;
     return;
}
return 0;
}

don't use a return statement at all when the function return type is void.

void printValue(int v)
{
   cout << v;
}

or just say return with nothing listed after it but a semicolon, that should work too.

You get the undefined reference because there is no getSales function anywhere. You declare it on line 12, but you don't have the function itself, which means you can't call it in lines 25 - 28. is the code starting on line 34 supposed to be the code inside the getSales function, perhaps? If that is what you intend, be advised that those lines are currently inside your main function.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.