### Homework Help

hello, i am stuck on a problem. we have a homework problem where we have to use if and else statements. i somewhat under stand them when we did simply payroll programs but now we have a bigger problem and i am getting extremely lost. here is the problem.

"There are three job classifications in a tire manufacturing company. There are hourly employees, piece count employees, and sales employees. All these employees are paid based on each employee’s hourly pay rate. They are paid straight time for the first forty hours worked. Between forty and sixty hours worked, each employee is paid time-and-a-half. Double time is paid for all hours worked over sixty.

In addition to their hourly pay, piece count workers and sales employees are paid an additional amount. The additional amount paid to piece count workers is based on the number of tires produced by them. (The number of tires produced is referred to as the “piece count”.) The additional amount paid to sales employees is based on the dollar amount of sales made."

here is my code

 ``123456789101112131415161718192021222324252627282930313233343536373839404142`` ``````#include #include #include using namespace std; int main () { char etype; string ename; float hoursworked,grosspay,payrate,Ppay,comm,netsales,sales,pcount; cout << "Enter an employee name: "; getline(cin,ename); cout << "\nEnter the employee type. "; cout <<"\nH\tEnter if hourly employee. "; cout <<"\nP\tEnter is hourly plus piece credit."; cout <<"\nS\tEnter if sales plus commission"; cout <<"\nEnter your response here: "; cin >> etype; if(toupper(etype)!='H' || toupper(etype)!='P' || toupper(etype) !='S') { if(toupper(etype)=='H') { cout <<"\nEnter the hours worked: "; cin >> hoursworked; cout << "\nEnter the pay rate: "; cin >> payrate; if(hoursworked <= 40) grosspay= hoursworked * payrate; else if(hoursworked <= 60) grosspay= 40*payrate+1.5*payrate *(hoursworked-40); else grosspay= 70 *payrate+2*payrate*(hoursworked-60); } return 0; }``````

here are some things i dont understand (it isnt done)

i have a menu in my program.what do i need to do so that my output is different based on the variable my user enters? i.e if i enter "a" then the user will get a different set of results then if i had entered "b"

i am getting lost in if and else statements. i dont know exactly why i am using if else.

Last edited on
 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485`` ``````okay so after working on it and reading a bit more, i think that i am making progress but would like to know if i am in the right direction #include #include #include #include using namespace std; int main () { char etype; string ename; float hoursworked,grosspay,payrate,Ppay,comm,netpay,sales,pcount; cout << "Enter an employee name: "; getline(cin,ename); cout << "\nEnter the employee type. "; cout <<"\nH\tEnter if hourly employee. "; cout <<"\nP\tEnter is hourly plus piece credit."; cout <<"\nS\tEnter if sales plus commission"; cout <<"\nEnter your response here: "; cin >> etype; if(toupper(etype)=='H' || toupper(etype)=='P' || toupper(etype) =='S') { if(toupper(etype)=='H') { cout <<"\nEnter the hours worked: "; cin >> hoursworked; cout << "\nEnter the pay rate: "; cin >> payrate; if(hoursworked <= 40) grosspay= hoursworked * payrate; else { if(hoursworked <= 60) grosspay= 40*payrate+1.5*payrate *(hoursworked-40); else grosspay= 70 *payrate+2*payrate*(hoursworked-60);} } else if(toupper(etype)=='P') { cout <<"\nEnter the hours worked: "; cin >>hoursworked; cout << "\nEnter the pay rate: "; cin >> payrate; cout << "\nEnter piececount: "; cin >> pcount; if(pcount >= 1000) Ppay= grosspay + (.01f*pcount); else if (pcount < 5000) Ppay= grosspay + (.015f * pcount); else Ppay= grosspay + (.02f * pcount); } else if(toupper(etype)=='S') { cout <<"\nEnter the hours worked: "; cin>> hoursworked; cout <<"\nEnter the pay rate : "; cin >> payrate; cout <<"\nEnter amount of sales: "; cin >> sales; if(sales >= 5000) netpay=grosspay+(.15f*sales); else if(sales <10000) netpay=grosspay+(.2368f*sales); else if(sales <25000) netpay=grosspay +(.2455f*sales); else netpay=grosspay + (.2521f *sales); } return 0; }``````
Last edited on
Could you use code tags?
A switch statement is very useful for menus!
my apologies, how do i use code tags?
a switch? i shall look in my book about that
When you click the edit button, on the right hand side, you should find a symbol that looks like
 <>
. Select your entire code and click this symbol, then press submit

Switch statements are a cleaner version of if-statements where you have one test case that can result in multiple values. The beginning of a switch statement starts with calling value to be tested. Then within the body, you have "cases" where each case corresponds to a possible state of the value being tested. ex

 ``12345678`` ``````switch ( val < info ) { case 1: level = left->__insert__(val); break; case 0: level = right->__insert__(val); break; }``````

Also after the correct state if found, a break statement is needed in other for the code to leave the switch block
okay thank you i will use that next time

also i like that. i am going to read and practice that. unfortunately we have to use if else statements.
why are you using "toupper"??? are you required to use that?? because I think its possible to work your way around this problem without <ctype> library.
@jkevin

Use of toupper is OK, except the OP should do it once for the variable `etype`, not multiple times.

There are several versions of toupper, 1 C version and 2 C++ versions:

 http://www.cplusplus.com/reference/locale/ctype/toupper/ http://www.cplusplus.com/reference/locale/toupper/

@ominous

It would be good if you could edit your post to use code tags, now rather than next time.
Topic archived. No new replies allowed.