I'm still a noon trying to teach myself C and I'm using the Prada C Primer book to help me along. This program is supposed to have you choose a pay rate then calculate the gross tax and net then display them. It is supposed to exit if a 5 is entered to quit but the loop isn't behaving as I expected. Can someone please explain how and where I went wrong?
Code:
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define RATE1 .15
#define RATE2 .20
#define RATE3 .25
#define GROSS1 300
#define GROSS2 450
#define TAX1 (GROSS1 * RATE1)
#define TAX2 (TAX1 + (RATE2 * (gross - GROSS1)))
#define TAX3 (TAX1 + TAX2 + (RATE3 * (gross - GROSS2)))
#define WAGE1 8.75
#define WAGE2 9.33
#define WAGE3 10.00
#define WAGE4 11.20
int pay_Rate;
float hourz, gross, net, tax, wage;
int main(int argc, const char **argv)
{
printf("*****************************************************************\n");
printf("Enter the number corresponding to the desired pay rate or action:\n");
printf("1) $8.75 2) $9.33\n");
printf("3) $10.00 4) $11.20\n");
printf("5) quit\n");
printf("*****************************************************************\n");
while((scanf("%d", &pay_Rate) > 0) || (scanf("%d", &pay_Rate) < 5) || (scanf("%d", &pay_Rate) != 5))
{
scanf("%d", &pay_Rate);
switch(pay_Rate)
{
case 1:
wage = WAGE1;
break;
case 2:
wage = WAGE2;
break;
case 3:
wage = WAGE3;
break;
case 4:
wage = WAGE4;
break;
case 5:
printf("quit\n");
continue;
default:
printf("you entered an invalid number.\n");
printf("Enter a valid number.\n");
continue;
}
printf("\nNumber of hourz worked this week: ");
scanf("%f", &hourz);
if(hourz > 40)
gross = ((hourz - 40) * (1.5 * wage)) + (40 * wage);
else
gross = hourz * wage;
if(gross <= GROSS1)
tax = RATE1 * gross;
else if(gross <= GROSS2)
tax = TAX2;
else
tax = TAX3;
net = gross - tax;
printf("gross is %.2f minus tax %.2f is a net of %.2f.\n", gross, tax, net);
printf("\nEnter another pay rate: ");
}
printf("end of run");
return 0;
}