I was asked

"This program should calculate which of four company divisions had the highest sales for the last year. The program should ask for the annual sales for the four divisions. The function should calculate which division has the highest amount in sales and return that amount to the calling program. The program should not accept sales amounts less than 0. The output should look like the example below.

Highest division sales for the prior year: $xxx,xxx,xxx.xx"

I'm getting the errors:

c:\data - vs2008\winner\winner\winner.cpp(90) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\data - vs2008\winner\winner\winner.cpp(90) : error C2065: 'saleDept1' : undeclared identifier
1>c:\data - vs2008\winner\winner\winner.cpp(90) : error C2065: 'saleDept2' : undeclared identifier
1>c:\data - vs2008\winner\winner\winner.cpp(90) : error C2065: 'saleDept3' : undeclared identifier
1>c:\data - vs2008\winner\winner\winner.cpp(90) : error C2065: 'saleDept4' : undeclared identifier
1>c:\data - vs2008\winner\winner\winner.cpp(92) : error C2143: syntax error : missing ';' before '<<'
1>c:\data - vs2008\winner\winner\winner.cpp(92) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\data - vs2008\winner\winner\winner.cpp(94) : error C2059: syntax error : 'return'
1>c:\data - vs2008\winner\winner\winner.cpp(96) : error C2059: syntax error : '}'
1>c:\data - vs2008\winner\winner\winner.cpp(96) : error C2143: syntax error : missing ';' before '}'
1>c:\data - vs2008\winner\winner\winner.cpp(96) : error C2059: syntax error : '}'
1>c:\data - vs2008\winner\winner\winner.cpp(99) : error C2143: syntax error : missing ';' before '{'
1>c:\data - vs2008\winner\winner\winner.cpp(99) : error C2447: '{' : missing function header (old-style formal list?)

What am I doing wrong?

#include<iostream>
#include<iomanip>

using namespace std;

double winner(double subAmount1, double subAmount2, double subAmount3, double subAmount4); //prototype

int main()

{
    //declare variables

    double saleDept1 = 0.0;
    double saleDept2 = 0.0;
    double saleDept3 = 0.0;
    double saleDept4 = 0.0;
    double finalwinner = 0.0;

    //get input

    while(cin)
    {
        cout << "Please enter Division one's highest sales";
        cin >> saleDept1;
        
        if(saleDept1 > 0)
        {
            cout << "Input Good";
            cout << endl;
        }
        else
        {
            cout << "Please enter a value higher than Zero" << endl;
            return 0;
        }
    }//end while
    
    while(cin)
    {
        cout << "Please enter Division two's highest sales";
        cin >> saleDept2;
        
        if(saleDept2 > 0)
        {    
            cout << "Input Good";
            cout << endl;
        }
        else
        {
            cout << "Please enter a value higher than Zero" << endl;
            return 0;
        }
    }//end while

    while(cin)
    {
        cout << "Please enter Division three's highest sales";
        cin >> saleDept3;
        
        if(saleDept3 > 0)
        {
            cout << "Input Good";
            cout << endl;
        }
        else
        {
            cout << "Please enter a value higher than Zero" << endl;
            return 0;
        }

    }//end while

        cout << "Please enter Division fours's highest sales";
        cin >> saleDept4;
        
        if(saleDept4 > 0)
        {
            cout << "Input Good";
            cout << endl;
        }
        else
        {
            cout << "Please enter a value higher than Zero" << endl;
            return 0;
        }
    }// end while

    //Call function

    finalwinner =  winner(saleDept1, saleDept2, saleDept3, saleDept4);

    cout << "Highest division sales for the prior year: $" << finalwinner << endl;

    return 0;

}//end main

double winner(double subAmount1, double subAmount2, double subAmount3, double subAmount4)
{
    double deptTemp1 = 0.0;
    double deptTemp2 = 0.0;
    double final = 0.0;

    if(subAmount1 < subAmount2)
    {
        deptTemp1 = subAmount1;
    }
    else
    {
        deptTemp1 = subAmount2;
    }

    if(subAmount3 < subAmount4)
    {
        deptTemp2 = subAmount3;
    }
    else
    {
        deptTemp2 = subAmount4;
    }

    if (deptTemp1 < deptTemp2)
    {
        final = deptTemp1;
    }
    else
    {
        final = deptTemp2;
    }
return final;

}//end winner

Why are you returning 0 from your 'else' conditions..?? why not let processing continue throughout the loop?

Stuff like this can cause your program to not work the way you think it will work.

Why are you returning 0 from your 'else' conditions..?? why not let processing continue throughout the loop?

Stuff like this can cause your program to not work the way you think it will work.

Thank you.

Duelly noted! removing the zero's gave me:

1>c:\data - vs2008\winner\winner\winner.cpp(86) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\data - vs2008\winner\winner\winner.cpp(86) : error C2065: 'saleDept1' : undeclared identifier
1>c:\data - vs2008\winner\winner\winner.cpp(86) : error C2065: 'saleDept2' : undeclared identifier
1>c:\data - vs2008\winner\winner\winner.cpp(86) : error C2065: 'saleDept3' : undeclared identifier
1>c:\data - vs2008\winner\winner\winner.cpp(86) : error C2065: 'saleDept4' : undeclared identifier
1>c:\data - vs2008\winner\winner\winner.cpp(88) : error C2143: syntax error : missing ';' before '<<'
1>c:\data - vs2008\winner\winner\winner.cpp(88) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\data - vs2008\winner\winner\winner.cpp(90) : error C2059: syntax error : 'return'
1>c:\data - vs2008\winner\winner\winner.cpp(92) : error C2059: syntax error : '}'
1>c:\data - vs2008\winner\winner\winner.cpp(92) : error C2143: syntax error : missing ';' before '}'
1>c:\data - vs2008\winner\winner\winner.cpp(92) : error C2059: syntax error : '}'
1>c:\data - vs2008\winner\winner\winner.cpp(95) : error C2143: syntax error : missing ';' before '{'
1>c:\data - vs2008\winner\winner\winner.cpp(95) : error C2447: '{' : missing function header (old-style formal list?)

#include<iostream>
#include<iomanip>

using namespace std;

double winner(double subAmount1, double subAmount2, double subAmount3, double subAmount4); //prototype

int main()

{
	//declare variables

	double saleDept1 = 0.0;
	double saleDept2 = 0.0;
	double saleDept3 = 0.0;
	double saleDept4 = 0.0;
	double finalwinner = 0.0;

	//get input

	while(cin)
	{
		cout << "Please enter Division one's highest sales";
		cin >> saleDept1;

		if(saleDept1 > 0)
		{
			cout << "Input Good";
			cout << endl;
		}
		else
		{
			cout << "Please enter a value higher than Zero" << endl;
		}
	}//end while

	while(cin)
	{
		cout << "Please enter Division two's highest sales";
		cin >> saleDept2;

		if(saleDept2 > 0)
		{    
			cout << "Input Good";
			cout << endl;
		}
		else
		{
			cout << "Please enter a value higher than Zero" << endl;
		}
	}//end while

	while(cin)
	{
		cout << "Please enter Division three's highest sales";
		cin >> saleDept3;

		if(saleDept3 > 0)
		{
			cout << "Input Good";
			cout << endl;
		}
		else
		{
			cout << "Please enter a value higher than Zero" << endl;
		}

	}//end while

	cout << "Please enter Division fours's highest sales";
	cin >> saleDept4;

	if(saleDept4 > 0)
	{
		cout << "Input Good";
		cout << endl;
	}
	else
	{
		cout << "Please enter a value higher than Zero" << endl;
	}

	//Call function

	finalwinner =  winner(saleDept1, saleDept2, saleDept3, saleDept4);

	cout << "Highest division sales for the prior year: $" << finalwinner << endl;


}//end main

double winner(double subAmount1, double subAmount2, double subAmount3, double subAmount4)
{
	double deptTemp1 = 0.0;
	double deptTemp2 = 0.0;
	double final = 0.0;

	if(subAmount1 < subAmount2)
	{
		deptTemp1 = subAmount1;
	}
	else
	{
		deptTemp1 = subAmount2;
	}

	if(subAmount3 < subAmount4)
	{
		deptTemp2 = subAmount3;
	}
	else
	{
		deptTemp2 = subAmount4;
	}

	if (deptTemp1 < deptTemp2)
	{
		final = deptTemp1;
	}
	else
	{
		final = deptTemp2;
	}
	return final;

}//end winner

^--All fixed dude.

*You just had the problem of stray brackets and returning 0's...*

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