Help with functions

This is a discussion on Help with functions within the C++ Programming forums, part of the General Programming Boards category; Can anyone help me with this question? I have only done basic C stuff, and I don't think we've touched ...

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    1

    Help with functions

    Can anyone help me with this question? I have only done basic C stuff, and I don't think we've touched upon Functions yet:-

    Write a program to input the number of workers followed by hours worked, hourly rate of pay, overtime rate of pay, status (married or single) for each.

    The main program must use separate functions and appropriate parameters.

    Suggested functions include:
    a) Calculate the gross pay (overtime rate is paid for any number of hours above 40);
    b) Calculate the amount of tax paid (25% if Married and 30% if Single);
    (c) Display all the details on a payslip.

    Many thanks for any help you may be able to offer

    Stefanie <3

  2. #2
    Registered User Strider's Avatar
    Join Date
    Aug 2001
    Posts
    149
    The use of basic functions follows a standard format:
    Code:
    //Declare prototypes
    // return_type function_name (parameter_one, parameter_two, ...);
    float CalculatePay(float hours, float hourlyPay, float overtime);
    // ... and so on
    
    // call the function
    int main()
    {
        float hours, hourlyPay, overtime, totalPay;
    
        // read in your data - i.e. cin >> hours; .........
    
        // send data to the function
        totalPay = CalculatePay(hours, hourlyPay, overtime);
    
        return 0;
    }
    
    // define the function
    float CalculatePay(float hours, float hourlyPay, float overtime)
    {
        // code for what the function is supposed to do
    
        // return a value if there is a return type - not void
        return some_float_value;
    }
    This should be enough to get you started. If you have problems once you have started, let me know.

    David
    One Ring to rule them all, One Ring to find them,
    One Ring to bring them all and in the darkness bind them
    In the Land of Mordor where the Shadows lie.

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    30
    Hi Stefanie.

    Are you at Tameside College?

    We have just done a very similar excersise.
    Homer

    D'OH!

    mmmmmmmm... iterations

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Void Functions Help
    By bethanne41 in forum C++ Programming
    Replies: 1
    Last Post: 05-09-2005, 06:30 PM
  2. Functions and Classes - What did I do wrong?
    By redmage in forum C++ Programming
    Replies: 5
    Last Post: 04-11-2005, 12:50 PM
  3. calling functions within functions
    By edd1986 in forum C Programming
    Replies: 3
    Last Post: 03-29-2005, 03:35 AM
  4. Factory Functions HOWTO
    By GuardianDevil in forum Windows Programming
    Replies: 1
    Last Post: 05-01-2004, 02:41 PM
  5. Shell functions on Win XP
    By geek@02 in forum Windows Programming
    Replies: 6
    Last Post: 04-19-2004, 06:39 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21