I am having a tough time grasping functions =/ the book we use is pretty much useless.

My problems are

1) Knowing what to put into the function ( )
2) How to validate it ( nothing in the book about it)

Any help or ideas I will greatly love and enjoy.

"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 division's quarterly sales figure, validates the input then returns a valid sales figure for that quarter. 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.

Do not accept dollar amounts less than 0."

#include <cstdlib>
#include <iostream>

using namespace std;

double getSales(double,double,double,double)
void findHighest()
void validate(double &)

int main(int argc, char *argv[])
{
    
    
    return 0;
    
    
}


void validate(double)
{
    while( num !=0) // cannot = 0
}

double getSales()
{
double Div_ne, Div_se, Div_nw, Div_sw;

    cout << "Enter the Sales for the NE division\n";
    cin >> Div_ne;
    void validate(double &)

    cout << "Enter the Sales for the SE division\n";
    cin >> Div_se;
    void validate(double &)

    cout << "Enter the Sales for the NW division\n";
    cin >> Div_nw;
    void validate(double &)

    cout << "Enter the Sales for the SW division\n";
    cin >> Div_sw;
    void validate(double &)

}

findHighest()
{
    cout << "Sales for the NE division are: " << Div_ne << endl;
    cout << "Sales for the SE division are: " << Div_se << endl;
    cout << "Sales for the NW division are: " << Div_nw << endl;
    cout << "Sales for the SW division are: " << Div_sw << endl;
}

Well how a function works, is that it takes arguments, and then passes the value to the function.

Now, when it passes that value, it isn't passing the variable itself. This is how all variables are unique to their function.

I'm fairly new to C++ myself so I don't think I should be explaining it in too much detail. Here is a really good site on functions:

http://www.cplusplus.com/doc/tutorial/functions.html

www.cplusplus.com is a great site in general for reference and tutorials.

There's nothing about validating in your book because it's not standard, it's something that you make it yourself.

* double getSales() is passed the name of a division. It asks the user for a division's quarterly sales figure, validates the input then returns a valid sales figure for that quarter. 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.

Do not accept dollar amounts less than 0."

#include <cstdlib>
#include <iostream>

using namespace std;

double getSales(double,double,double,double)
void findHighest([B]double[/B])
void validate(double &)

Now main is where you call these functions. Functions take inputs (arguments/parameters) and may return, but not necessarily. If you want an analogy (albeit strange..) main "hires" or call maids who do certain activities. You call cleaning maid, give it a mop or a vacuum, and it does it. You call a cook, give them ingredients, they cook for you. Wow, that was strange. And not in a good way. Anyway.. my point is that main is where you want to call these functions.

int main(int argc, char *argv[])
{
    cleanFloor(vacuum);
   
    sandwich = cookFood(bread, cheese, ham);
    
    return 0;
    
    
}
void validate(double [B]sales[/B]) // you want this argument to have a name to refer to, right?
{
    while( num !=0) // cannot = 0
    {
         //what is this while loop for?
    }
}
double getSales()
{
double Div_ne, Div_se, Div_nw, Div_sw; // they should be declared in main. just copy and paste before calling "getSales" function. This also means you need to pass those div stuffs as arguments.

    cout << "Enter the Sales for the NE division\n";
    cin >> Div_ne;
    validate(double [B]Div_ne[/B]) // you want to tell the "validate" function what it should validate, right? Do the same for the rest. And take void out before validate function. You already specified what type "validate" function returns.

    cout << "Enter the Sales for the SE division\n";
    cin >> Div_se;
    void validate(double &)

    cout << "Enter the Sales for the NW division\n";
    cin >> Div_nw;
    void validate(double &)

    cout << "Enter the Sales for the SW division\n";
    cin >> Div_sw;
    void validate(double &)

}
findHighest() // Div_ne and all the others are not declared in this function. there for you need to pass those as arguments.
{
    cout << "Sales for the NE division are: " << Div_ne << endl;
    cout << "Sales for the SE division are: " << Div_se << endl;
    cout << "Sales for the NW division are: " << Div_nw << endl;
    cout << "Sales for the SW division are: " << Div_sw << endl;

   some kind of comparison statements should be here to decide which divition
    
}

mm that's all i can arse to write down atm..... let me know if you need more help.

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