Hi,
Sorry for my late reply, I have been busy trying to rent a house :+)
Here are some things to help you out :+)
It's a good idea to declare, initialise and optionally comment each variable, one per line:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
#include <iostream>
using namespace std; // avoid doing this, do std::cout etc instead, Google as to why this is
int main(){
double managersalary, cooksfixedrate, salespersonsalary, commissionrate, cookstotalworkinghours, salespersontotalsales, totalincome;
, manager, cooks, salesperson;
const double managersalary = 1000.00;
const double cooksfixedrate = 15.00;
const double salespersonsalary = 300.00;
const double commissionrate = 0.085;
double cookstotalworkinghours = 0.0;
double salespersontotalsales = 0.0;
double totalincome = 0.0;
const double cooksnormalhours = 30.0; // normal number of hours per week
const double overtimefactor = 1.5; // Time and a half rate for overtime
position = manager, cooks, salesperson;
|
I added extra variables so you don't have magic numbers like
30.0
and
1.5
littered throughout the code, use these variable names in your code instead of the numbers.
Line 17, 22, 36:
The
=
operator is for assignment, you need the
==
operator which is for equality comparison.
With the if else if statements, rather than put the code for each action in the statement itself, consider having each if or else if call a function. This will tidy up the code considerably, and is good practise.
You don't need variables for each of the roles cook etc, just use the
position
variable.
Another way to achieve the same thing is to use a
switch
statement, with each
case:
calling a function. First, call a void function which shows a menu of options. Provide a
quit
option as well as an option for each of the roles cook etc. With the
switch
, provide a
default:
case to catch bad input, and put the whole thing into a
bool
controlled
while
loop:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
ShowMenu(); // put a declaration for this before main, and provide a definition for it after main.
// same for other functions below
//get user input
char position = 'z' ; // can be 'm' , 'c' , or 's' for each role
std::cin >> position;
bool quit = false;
while (!quit) {
switch (position) {
case 'm' :
case 'M' : // allow for upper and lower case input
// call function to process manager payment
break;
case 's' :
case 'S' : // allow for upper and lower case input
// call function to process Salesperson payment
break;
case 'c' :
case 'C' : // allow for upper and lower case input
// call function to process Cook payment
break;
case 'q' :
case 'Q' : // allow for upper and lower case input
// user wants to quit
quit = true;
break;
default:
// print message about bad input
break;
} // end switch
} //end while
|
On line 32 there is a problem with your parentheses not being in the right places.
With the number of hours worked, there should be some validation of the amount entered. Negative values are obviously wrong, and there is probably some sort of maximum as well.
Good Luck - we all look forward to seeing your new code <8+D