Using Borland 4.5

I think I got most the program done but its hard for me to setup functions with returning names and values.

Problems States:

Winning Division:

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 that are called by main.

-double getSales()is passed the name of a division. It ask the user for a division'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 figure largest and prints the name of the high grossing division, along with its sales figures.

Input Validation: Do not accept dollar amounts less than \$0.00

I really don't understand the first function that is underlined.

This is what I have so far.

``````#include <iostream.h>
#include <iomanip.h>
#include <stdlib.h>

double getSales(double, double, double, double);
void findHighest(double, double, double, double);

int main()

{
double Neast, Seast, Nwest, Swest;

cout << "This program determines which of a company's four divisions had " ;
cout << "greatest sales for a quarter." << endl;

cout << "Northeast Division: " << endl;
Neast = getSales();

cout << "Southeast Division: " << endl;
Seast = getSales();

cout << "Northwest Division: " << endl;
Nwest = getSales();

cout << "Southwest Division: " << endl;
Swest = getSales();

findHighest();

}

double getSales()
{
double sales;

cout << "What is the sales for this division?" << endl;
cin >> sales;

if(sales < 0)
{

cout << "  Error: Only enter sale figures above zero" << endl;
exit(0);
}

return sales;

void findHighest(double Neast, double Seast, double Nwest, double Swest)

{

cout << setiosflags(ios::showpoint | ios::fixed);
cout << setprecision(2);

if (Neast > Seast && Neast > Nwest)
{
if(Neast > Swest)
{
cout << "The Northeast division had the greatest number of sales, \$";
cout << Neast << endl;
}
}

if (Seast > Neast && Seast > Nwest)
{
if(Seast > Swest)
{
cout << "The Southeast division had the greatest number of sales, \$";
cout << Seast << endl;
}
}

if (Nwest > Neast && Nwest > Seast)
{
if(Nwest > Swest)
{
cout << "The Northwest division had the greatest number of sales, \$";
cout << Nwest << endl;
}

}

if <Swest > Neast && Swest > Seast)
{
if(Swest > Nwest)
{
cout << "The Southwest divsion had the greatest number of sales, \$";
cout << Swest << endl;
}
}
}``````

## All 6 Replies

Looks pretty good to me, what is the problem with that function. Your prototype at the top must match your function definition.

its my functions how I state them the context isn't clear and I keep getting errors.

I've been trying to clean it up on my own, can you take a look?

updated one

``````#include <iostream.h>
#include <iomanip.h>
#include <stdlib.h>

double getSales();
void findHighest(double, double, double, double);

int main()

{
double Neast, Seast, Nwest, Swest;

cout << "This program determines which of a company's four divisions had " ;
cout << "greatest sales for a quarter." << endl;

cout << "Northeast Division: " << endl;
Neast = getSales();

cout << "Southeast Division: " << endl;
Seast = getSales();

cout << "Northwest Division: " << endl;
Nwest = getSales();

cout << "Southwest Division: " << endl;
Swest = getSales();

findHighest(double, double, double, double);

return 0;

}

double getSales()
{
double sales;

cout << "What is the sales for this division?" << endl;
cin >> sales;

if(sales < 0)
{

cout << "  Error: Only enter sale figures above zero" << endl;
exit(0);
}

return sales;
}
void findHighest(double Neast, double Seast, double Nwest, double Swest)

{

cout << setiosflags(ios::showpoint | ios::fixed);
cout << setprecision(2);

if (Neast > Seast && Neast > Nwest)
{
if(Neast > Swest)
{
cout << "The Northeast division had the greatest number of sales, \$";
cout << Neast << endl;
}
}

if (Seast > Neast && Seast > Nwest)
{
if(Seast > Swest)
{
cout << "The Southeast division had the greatest number of sales, \$";
cout << Seast << endl;
}
}

if (Nwest > Neast && Nwest > Seast)
{
if(Nwest > Swest)
{
cout << "The Northwest division had the greatest number of sales, \$";
cout << Nwest << endl;
}

}

if <Swest > Neast && Swest > Seast)
{
if(Swest > Nwest)
{
cout << "The Southwest divsion had the greatest number of sales, \$";
cout << Swest << endl;
}
}
}``````

the context isn't clear

I don't fully understand what you mean by that.

I keep getting errors

What are they?

Line 30 is definitely not correct, you do not need the datatype when calling the function, just the parameters that you are passing to it.

oh ok

I made it through to my second function

``````//
//
//
#include <iostream.h>
#include <iomanip.h>
#include <stdlib.h>

double getSales();
void findHighest(double, double, double, double);

int main()

{
double Neast, Seast, Nwest, Swest;

cout << "This program determines which of a company's four divisions had " ;
cout << "greatest sales for a quarter." << endl;

cout << "Northeast Division: " << endl;
Neast = getSales();

cout << "Southeast Division: " << endl;
Seast = getSales();

cout << "Northwest Division: " << endl;
Nwest = getSales();

cout << "Southwest Division: " << endl;
Swest = getSales();

findHighest(Neast, Seast, Nwest, Swest);

return 0;

}

double getSales()
{
double sales;

cout << "What is the sales for this division?" << endl;
cin >> sales;

if(sales < 0)
{

cout << "  Error: Only enter sale figures above zero" << endl;
exit(0);
}

return sales;
}
void findHighest(double, double, double, double)

{

cout << setiosflags(ios::showpoint | ios::fixed);
cout << setprecision(2);

if (Neast > Seast && Neast > Nwest)
{
if(Neast > Swest)
{
cout << "The Northeast division had the greatest number of sales, \$";
cout << Neast << endl;
}
}

if (Seast > Neast && Seast > Nwest)
{
if(Seast > Swest)
{
cout << "The Southeast division had the greatest number of sales, \$";
cout << Seast << endl;
}
}

if (Nwest > Neast && Nwest > Seast)
{
if(Nwest > Swest)
{
cout << "The Northwest division had the greatest number of sales, \$";
cout << Nwest << endl;
}

}

if ( <Swest > Neast && Swest > Seast)
{
if(Swest > Nwest)
{
cout << "The Southwest divsion had the greatest number of sales, \$";
cout << Swest << endl;
}
}
}``````

I get these errors

Compiling WINNINGD.CPP:
Error WINNINGD.CPP 63: Undefined symbol 'Neast' in function findHighest(double,double,double,double)
Error WINNINGD.CPP 63: Undefined symbol 'Seast' in function findHighest(double,double,double,double)
Error WINNINGD.CPP 63: Undefined symbol 'Nwest' in function findHighest(double,double,double,double)
Error WINNINGD.CPP 65: Undefined symbol 'Swest' in function findHighest(double,double,double,double)
Error WINNINGD.CPP 91: Expression syntax in function findHighest(double,double,double,double)
Error WINNINGD.CPP 99: If statement missing ) in function findHighest(double,double,double,double)
Error WINNINGD.CPP 99: Compound statement missing } in function findHighest(double,double,double,double)

For a function:
In the prototype (up at the top) the names of the parameters are optional (with the prototype you are simply telling the compiler, "there's a function that looks like this that's coming up", hence the names aren't important)

When invoking the function, just the names of the parameters are required (the compiler already knows their type).

In the function definition (in this case at the bottom) both the type and names of the parameters are required (you need the types to specify what the function should expect and the names so you can operate with them in the function body).

So, line 55 is the culprit here.

Yes! I got it Thanks!

``````#include <iostream.h>
#include <iomanip.h>
#include <stdlib.h>

double getSales();
void findHighest(double, double, double, double);

int main()

{
double Neast, Seast, Nwest, Swest;

cout << "This program determines which of a company's four " << endl;
cout << "divisions had the greatest sales for a quarter." << endl;

cout << "Northeast Division: " << endl;
Neast = getSales();

cout << "Southeast Division: " << endl;
Seast = getSales();

cout << "Northwest Division: " << endl;
Nwest = getSales();

cout << "Southwest Division: " << endl;
Swest = getSales();

findHighest(Neast, Seast, Nwest, Swest);

return 0;

}

double getSales()
{
double sales;

cout << "What is the sales for this division?" << endl;
cin >> sales;

if(sales < 0)
{

cout << "  Error: Only enter sale figures above zero" << endl;
exit(0);
}

return sales;
}
void findHighest(double Neast, double Seast, double Nwest, double Swest)

{

cout << setiosflags(ios::showpoint | ios::fixed);
cout << setprecision(2);

if (Neast > Seast && Neast > Nwest)
{
if(Neast > Swest)
{
cout << "The Northeast division had the greatest number of sales, \$";
cout << Neast << endl;
}
}

if (Seast > Neast && Seast > Nwest)
{
if(Seast > Swest)
{
cout << "The Southeast division had the greatest number of sales, \$";
cout << Seast << endl;
}
}

if (Nwest > Neast && Nwest > Seast)
{
if(Nwest > Swest)
{
cout << "The Northwest division had the greatest number of sales, \$";
cout << Nwest << endl;
}

}

if (Swest > Neast && Swest > Seast)
{
if(Swest > Nwest)
{
cout << "The Southwest divsion had the greatest number of sales, \$";
cout << Swest << endl;
}
}
}``````
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.