new to C++ and need help

This is a discussion on new to C++ and need help within the C++ Programming forums, part of the General Programming Boards category; I have a project for class and I'm stuck. I am no where near finished with the program. nor am ...

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    10

    new to C++ and need help

    I have a project for class and I'm stuck. I am no where near finished with the program. nor am I asking anyone to write it for me, I'm just asking for help because I'm stuck. Sorry this thing is so long. Here is what the program is supposed to do.....

    You are to write a program that makes use of functions, switch statement(s), and a for loop. The program will include a main function that is a driver only, i.e., it will create/supply data to the function(s) that calculater salaries for the individuals and the companies payroll (all salaries totaled).
    The personnel data follows (in the form of Name - Employee ID - Base Salary - Bonus )
    Employee One - 101 - 2000 - 1400
    Employee Two - 102 - 2000 - 600
    Employee Three - 103 - 2000 - 350
    Employee Four - 104 - 2000 - 4500
    Employee Five - 105 - 2000 - 1500
    You may complete this table with a Payed column that will display Salary + Bonus for every employee and below the employees you would supply a "Sum" row. In any event, I want two questions to be answered.
    How much do we pay each employee?
    What is our payroll?

    But our professor has not went over how to make a table, nor have we read that in our book yet. but this is what i have so far, I'm really confused with the switch, I know how it works, but I'm just unsure of what info to put in.

    #include <cmath>
    #include <iostream>

    double sumMoney(double baseSalary, double bonus, double sum)
    {
    return baseSalary + bonus = sum;
    }
    double payroll(double baseSalary, double payRoll)
    {
    return (baseSalary * 5) = payRoll;
    }
    using namespace std;

    void main()
    {
    int employeeID, baseSalary=2000, bonus[4], j, n=5;

    cout << "Our payroll is: " << payroll(baseSalary, payRoll) << endl;
    cout << "Enter the bonus for employee 101: " ;
    cin >> bonus;
    for(j=1; j<= n; j++)
    {
    // Execute this block n times
    }

    }

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >I'm really confused with the switch, I know how it works, but I'm just unsure of what info to put in.
    Perhaps you should ask your instructor about that one. A switch makes little sense by my interpretation of the requirements. The way I see it, the user is to enter the data for N records and then the program prints the totals for each record as well as a running total of them all, like so:
    Code:
    Name   ID   BaseSalary   Bonus   TotalPay
    ----   --   ----------   -----   --------
    One    101  2000         1400    3400
    Two    102  2000         600     2600
    Three  103  2000         350     2350
    Four   104  2000         4500    6500
    Five   105  2000         1500    3500
    
    Total Payroll: 18350
    There's no need for a switch with that functionality, simply loop and ask for each record, then calculate the totals for that record, add them to the running total and print them. Iterate until you reach N records and then print the running total.

    -Prelude
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    362
    Kristina,

    Seems that your professor is looking for you to prompt for the Employee ID and run that value through a SWITCH statement, calling the function in each case element including the appropriate bonus value as an argument in the function call.

    This would also necessitate the incorporation of a flag to ensure that an Employee ID, once added to the running total, would not be added again.

    Just offering a suggestion as to where the 'switch' statement comes into play.

    It's an academic exercise so don't be too concerned about the efficiency of the code. Real world, I wouldn't do it this way, either!

    "When the only tool you own is a hammer, every problem begins to resemble a nail." Abraham Maslow

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