-
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
}
}
-
>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
-
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!
:)