Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,271 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,444 people online right now. Registration is fast and FREE... Join Now!




Passing values to a function

 
Reply to this topicStart new topic

Passing values to a function

countess
15 Oct, 2006 - 12:53 AM
Post #1

New D.I.C Head
*

Joined: 15 Oct, 2006
Posts: 1


My Contributions
I'm having problem figuring out how to write the source code for a homework assignement and could really use some help.

Here the problem:

[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:

1. 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 it. It should be called once for each division.

2. 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]


CODE

//findHighest function definition
void findHighest()
{
       double sales1, sales2, sales3. sales4;
       double max = sales1;
      
       if(sales2 > max)
                max = sales2;
      
       if(sales3 > max)
                max = sales3;

       if(sales4 > max)
                max = sales4;
      
}


I think I have the second function worked out, but I'm not quite sure how to pass the names to the getSales() function or the four sales totals to the findHighest() function.

Also I can't figure out how I would get the findHighest function to print out the winning division's name, though I'm guessing it has to do with figuring out how to define the getSales() function.

Any help would be really appreciated! smile.gif
User is offlineProfile CardPM
+Quote Post

gregoryH
RE: Passing Values To A Function
15 Oct, 2006 - 01:20 AM
Post #2

D.I.C Regular
Group Icon

Joined: 4 Oct, 2006
Posts: 417


Dream Kudos: 50
My Contributions
To pass a variable into a function, you must set up the function with parameters.

Parameters have a type such as char, int, double. The typical function call with parameters is:return_type function_name(char param1, int param2)

There is no set order that you have to write the parameters (unless you want optional paramters), ie i can pass an int before a char. However, you must make the function call with the parameter in the sequence that you define. Have a look at this tutorial on Functional Decomposition to see parameter passing in action.
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/4/08 07:57PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month