Thread: Help with functions

  1. #1
    Registered User
    Join Date
    Dec 2001

    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
    The use of basic functions follows a standard format:
    //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.

    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
    Hi Stefanie.

    Are you at Tameside College?

    We have just done a very similar excersise.


    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, 05:30 PM
  2. Functions and Classes - What did I do wrong?
    By redmage in forum C++ Programming
    Replies: 5
    Last Post: 04-11-2005, 11:50 AM
  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, 01:41 PM
  5. Shell functions on Win XP
    By geek@02 in forum Windows Programming
    Replies: 6
    Last Post: 04-19-2004, 05:39 AM