help with salary calculator and loops

This is a discussion on help with salary calculator and loops within the C++ Programming forums, part of the General Programming Boards category; can someone please give me help with modifiying the following code, so that it can be used for 10 employees. ...

  1. #1
    Registered User
    Join Date
    Dec 2009
    Posts
    14

    help with salary calculator and loops

    can someone please give me help with modifiying the following code, so that it can be used for 10 employees.
    basically what it is is a salary calculator, the user inputs there hourly salary, and hours worked, and the it calculates their pay and any overtime (x1.5) over 35 hours.
    but i need 10 employees to be able to input their data, and didnt want to just copy the code 10 tens, so thought there may have been a loop or something i could use

    please help
    here is the code:

    ----------------------------------------------------------------------

    int main()
    {

    float hours=0.0,wage1=0.0,pay=0.0,overtime=0.0,overtimep ay=0.0,totalpay=0.0;

    cout<<"please enter wage: ";
    cin>>wage1;
    cout<<"Please enter hours worked: ";
    cin>>hours;

    pay=wage1*35;
    overtime=wage1*1.5;
    overtimepay=(hours-35)*overtime;
    totalpay=pay+overtimepay;

    if(hours<=35)
    {
    cout<<"Your weekley pay is: "<<pay;
    }
    else
    {
    cout<<"Your weekley pay + overtime is: "<<totalpay;
    }



    cin.ignore();
    cin.ignore();

    return 0;
    }

  2. #2
    Registered User
    Join Date
    Apr 2006
    Posts
    2,053
    First of all, when posting code, put it in a [code] block so that the indentation is preserved.

    As for your code, there are two things you need to do. Firstly you need to group all the information about a single enployer into a single class (or at least a struct). If a class, you should also put into methods all the things that you do with the data, such as fetch it and compute pay. Second, you need to create an array of 10 employees (since you know that the employees will always be 10). Then you loop for each employee, and do what you currently do for one employee.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

Popular pages Recent additions subscribe to a feed

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