My task is ask this from the user:
Enter the number corresponding to the desired pay rate or action:
1) $8.75/hr 2) $9.33/hr
3) $10.00/hr 4) $11.20/hr
5) quit
If choices 1 through 4 are selected, the program should request the hours
worked. The program should recycle until 5 is entered. If something other than
choices 1 through 5 is entered, the program should remind the user what the
proper choices are and then recycle. And i have to use switch
My code:
#include <stdio.h>
#define RATE1 8.75
#define RATE2 9.33
#define RATE3 10.00
#define RATE4 11.20
int main()
{
int rateSelected;
int weeklyHours;
double totalPayed, rateToCalculate;
printf("Enter the number corresponding to the desired pay rate or action:\n");
printf("1) %.2lf$/hr 2) %.2lf$/hr\n", RATE1, RATE2);
printf("3) %.2lf$/hr 4) %.2lf$/hr\n", RATE3, RATE4);
printf("5) Quit\n");
while ((scanf("%d", &rateSelected)) != EOF && rateSelected != 5)
{
if (rateSelected > 4)
{
printf("please enter a valid number:\n");
continue;
}
switch (rateSelected)
{
case 1:
rateToCalculate = RATE1;
break;
case 2:
rateToCalculate = RATE2;
break;
case 3:
rateToCalculate = RATE3;
break;
case 4:
rateToCalculate = RATE4;
break;
};
printf("please enter you weekly hours:\n");
scanf("%d", &weeklyHours);
totalPayed = weeklyHours * rateToCalculate;
printf("your paychack for this week is: %.2lf\n\n",totalPayed);
printf("Enter the number corresponding to the desired pay rate or action:\n");
printf("1) %.2lf$/hr 2) %.2lf$/hr\n", RATE1, RATE2);
printf("3) %.2lf$/hr 4) %.2lf$/hr\n", RATE3, RATE4);
printf("5) Quit\n");
}
return 0;
}
How bad is it? And one thing didn't work for me is if a user put a letter its not cycling..(any suggestion for that too?)
Thank you,