Hi everyone! So I can't seen to get this program to compile and run. THis is exactly what I'm shooting to do:
This program should calculate which division in a company had the greatest sales
for a quarter. It should use the following functions:

  1. A function should ask the user for and return the quarterly sales
    figures for the company's Northeast, Southeast, Northwest, and Southwest divisions.
  2. A function should determine which division had the highest sales figures.

A message should be displayed indicating the leading division and its sales
figures for the quarter.

So I can't figure why this program won't compile any suggestions? Here is the code:

#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

// Function Prototypes
float division_input(string);
void highest_division(float, float, float, float);



int main()
{
      cout << "This program written  for cs102 Online." << endl;
      
      float nE, sE, nW, sW;

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

	highest_division(nE, sE, nW, sW); // Also prints the result

}
// *********Subroutine definitions below**********

float division_input 
{

      float quarter_sales = -1;
      
      while (quarter_sales < 0)
      {
            cout << "Enter the quarterly sales for " << division << "division:  $";
            cin >> quarter_sales;
            
      if (quarter_sales < 0)
         cout << "\nPlease enter a positive amount!";
     }
         
      return quarter_sales;
}

void highest_division (float nE, float nW, float sE, float sW)
{
     float highest_sales = nE;
     string greatest_division;
     
     greatest_division = "Northeast";
     
     if (nE > highest_sales)
     {
            highest_sales = nW;
            greatest_division = "Northwest";
            }
            
     if (sW > highest_sales)
     {
            highest_sales = sW;
            greatest_division = "Southwest";
            }
            
     if (sE > highest_sales)
     {
            highest_sales = sE;
            greatest_division = "Southeast";
            }
            
     cout << "\n\n The" << greatest_division << "division of the company had the highest\n"
     cout << " quarterly sales of $ ";
     cout << setprecision(4) << fixed;
     cout << highest_sales << endl;
}
     
    system("PAUSE");
    return 0;
}

what are the error messages? please post only the first two or three, not all one million of them .

And thank you for using code tags :cheesy:

float division_input 
{

That is syntax error. Are you trying to code a new function? There are other syntax errors too that you need to correct. The compiler will tell you what lines the errors are on.

Here are the error messages I'm getting:
under float division_input where { is it says invalid function declaration in function 'void highest_division(float,float,float,float)

please post exact error message. And read my previous post for suggestions to correct some of them. Yes, we already know there is a syntax error with function division_input . Now you need to figure out how to correct it.

#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

// Function Prototypes
float division_input(string);
void highest_division(float, float, float, float);



int main()
{
    ...
}
// *********Subroutine definitions below**********

float division_input 
{
     ...
}

Look at the red part, your function has four parameters, but you don't use them when you call your function.

System 'pause' should be avoided due to incompatibility.

Thank you so much for the help from both of you I really appreciate it! However I ran into one more probelm when I compile and run the program I can input all of the quarterly sales but it won't return what division has the highest sales it just quits the program after the last sales number is entered any particular reason why? THis is the new code:

#include <iostream>
 #include <iomanip>
 #include <string>
 
 using namespace std;
 
 // Function Prototypes
 float division_input(string);
 void highest_division(float, float, float, float);
 
 
 
 int main()
 {
       cout << "This program written for cs102 Online." << endl;
       
       float nE, sE, nW, sW;
 
     nE = division_input( "North East" );    
     sE = division_input( "South East" );    
     nW = division_input( "North West" );    
     sW = division_input( "South West" );    
 
     highest_division(nE, sE, nW, sW); // Also prints the result
 
 }
 // *********Subroutine definitions below**********
 
 float division_input (string division)
 {
 
       float quarter_sales = -1;
       
       while (quarter_sales < 0)
       {
            cout << "Enter the quarterly sales for " << division << " division:  $";
             cin >> quarter_sales;
             
       if (quarter_sales < 0)
          cout << "\nPlease enter a positive amount!";
      }
          
       return quarter_sales;
 }
 
 void highest_division (float nE, float nW, float sE, float sW)
 {
      float highest_sales = nE;
      string greatest_division;
      
      greatest_division = "Northeast";
      
      if (nE > highest_sales)
      {
             highest_sales = nW;
             greatest_division = "Northwest";
             }
             
      if (sW > highest_sales)
      {
             highest_sales = sW;
             greatest_division = "Southwest";
             }
             
      if (sE > highest_sales)
      {
             highest_sales = sE;
             greatest_division = "Southeast";
             }
             
     cout << "\n\n The" << greatest_division << "division of the company had the highest\n";
      cout << " quarterly sales of $ ";
      cout << setprecision(4) << fixed;
      cout << highest_sales << endl;
 }

When you call highest_divisions , you give the wrong order:

highest_division(nE, sE, nW, sW); // Also prints the result

You later declare it as nE, nW, sE, sW.

Also, in highest_divisions(), you have the following mistake:

void highest_division (float nE, float nW, float sE, float sW)
 {
      float highest_sales = nE;
      string greatest_division;
      
      greatest_division = "Northeast";
      
      if (nE > highest_sales)
      {
             highest_sales = nW;
             greatest_division = "Northwest";
             }

[edit]You might want a space in the cout call so that the text doesn't squish:

cout << "\n\n The" << greatest_division << "division of the company had the highest\n";

[/edit]

Hope this helps

I compiled your latter source code, and it worked fine. I could input the four numbers and it would give me output. You say it quits before it outputs the text? If you are using Visual Studio, if you run the program normally in console mode, it will close after it does its last command. If you are using Visual Studio, select the Start without debugging option. It's CTRL-F5. Otherwise, if you are on a linux system, pause is not a recognized command. If you run it at the command line though, you should still see the output.

P.S. It always helps to include in your original questions things like operating system and compiler.

I guess this problem is fixed. The final code should look something like:

#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

// prototypes
float division_input(string);
void highest_division(float, float, float, float);

int main()
{
    cout << "This program written  for cs102 Online." << endl;
      
    float nE=0,sE=0,nW=0,sW=0;

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

    highest_division(nE,sE,nW,sW); // Also prints the result

    return 0;
}
// *********Subroutine definitions below**********

float division_input(string division)
{
    float quarter_sales = -1;
      
    while (quarter_sales < 0)
    {
        cout << "Enter the quarterly sales for " << division << "division:  $";
        cin >> quarter_sales;
            
        if (quarter_sales < 0)
            cout << "\nPlease enter a positive amount!";
    }
         
    return quarter_sales;
}

void highest_division (float nE, float nW, float sE, float sW)
{
    float highest_sales = nE;
    string greatest_division;
     
    greatest_division = "Northeast";
     
    if (nE > highest_sales)
    {
        highest_sales = nW;
        greatest_division = "Northwest";
    }
            
    if (sW > highest_sales)
    {
        highest_sales = sW;
        greatest_division = "Southwest";
    }
            
    if (sE > highest_sales)
    {
        highest_sales = sE;
        greatest_division = "Southeast";
    }
            
    cout << "\n\nThe " << greatest_division << " division of the company had the highest\n";
    cout << "quarterly sales of $ ";
    cout << setprecision(4) << fixed;
    cout << highest_sales << endl;
}

I guess this problem is fixed. The final code should look something like:

#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

// prototypes
float division_input(string);
void highest_division(float, float, float, float);

int main()
{
    cout << "This program written  for cs102 Online." << endl;
      
    float nE=0,sE=0,nW=0,sW=0;

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

    highest_division(nE,sE,nW,sW); // Also prints the result

    return 0;
}
// *********Subroutine definitions below**********

float division_input(string division)
{
    float quarter_sales = -1;
      
    while (quarter_sales < 0)
    {
        cout << "Enter the quarterly sales for " << division << "division:  $";
        cin >> quarter_sales;
            
        if (quarter_sales < 0)
            cout << "\nPlease enter a positive amount!";
    }
         
    return quarter_sales;
}

void highest_division (float nE, float nW, float sE, float sW)
{
    float highest_sales = nE;
    string greatest_division;
     
    greatest_division = "Northeast";
     
    if (nE > highest_sales)
    {
        highest_sales = nW;
        greatest_division = "Northwest";
    }
            
    if (sW > highest_sales)
    {
        highest_sales = sW;
        greatest_division = "Southwest";
    }
            
    if (sE > highest_sales)
    {
        highest_sales = sE;
        greatest_division = "Southeast";
    }
            
    cout << "\n\nThe " << greatest_division << " division of the company had the highest\n";
    cout << "quarterly sales of $ ";
    cout << setprecision(4) << fixed;
    cout << highest_sales << endl;
}

The first 2 errors I mentioned are still present; the order of variables hasn't been corrected, leading to incorrect division names, and the first if statement in highest_division() should be nW > highest_sales .

This article has been dead for over six months. Start a new discussion instead.