I just started working with C and I'm reading C How to program. I really enjoy this book over all other programming books that I've read simply because this book has numerous exercises at the end of the chapters. This is helping me to really make sure that I have learned what the chapter was trying to teach. However, I've now run into a problem with some of the exercises. This one in particular has me stumped. The basic problem is that you are first supposed to find out what type of employee the person is (number from 1 to 4). If 1 (a manager) you receive a flat weekly salary. No problem there. If 2 (hourly employee) you also have to input your hours for the week and hourly rate. Then the program is supposed to output their weekly pay based off hours plus any possible overtime. There are 2 other employee types, but I haven't even gotten there yet because I'm having trouble calculating the hourly wage for employee 2. It keeps giving me back the results that I made 0.00 this week. Can anyone see from my code what I'm doing wrong? Thanks.
#include <stdio.h>
int main()
{
int empType = 0, hoursWorked = 0;
double hourlyRate = 0, overTime = 0;
printf("What type of employee are you?");
scanf("%d",&empType);
switch (empType){
case 1:
//manager
printf("You have made $500.00 this week.\n");
break;
case 2:
//hourly
printf("Please enter the number of hours you worked.");
scanf("%d", &hoursWorked);
printf("Please enter your hourly rate.");
scanf("%f", &hourlyRate);
if ( hoursWorked > 0 )
{
overTime = (double)((hoursWorked - 40) * (hourlyRate * 1.5));
}
printf("You made %.2f this week.\n", overTime);
break;
case 3:
//commission
break;
case 4:
//pieceworkers
break;
default:
printf("Sorry, I don't have functions written for that type of employee.");
break;
}
return 0;
}