I wrote this program for simple tax and gross pay calculation...
Im not able to execute the progam...Its compiling but the screen frozes while executing..
I know there is some simple mistake in my program... could any1 pls point out the mistake..
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
float tax_cal(float gross_pay);
float pay_cal(float payrate, int worked_hours);
void main()
{
//Variable declaration
int payrate_index, worked_hours;
float payrate,gross_pay, tax, net_pay;
//Displaying the menu
printf("\n");
printf("***********************************************************\n");
printf("* Enter the number corresponding to the desired pay rate: *\n");
printf("* 1 - £8.50/hr 2 - £9.90/hr *\n");
printf("* 3 - £22.40/hr 4 - £30.00/hr *\n");
printf("* 0 - Exit the program *\n");
printf("***********************************************************\n");
restart:
scanf("%d", &payrate_index);
printf("\nPlease enter the number of hours per week - ");
scanf("%d", &worked_hours);
switch(payrate_index)
{
case 0:
exit(0);
case 1:
payrate = 8.50;
gross_pay = pay_cal(payrate, worked_hours);
tax = tax_cal(gross_pay);
net_pay = gross_pay - tax;
printf("Net Pay - %.2f", net_pay);
break;
/*case 2:
payrate = 9.90;
gross_pay = pay_cal(payrate, worked_hours);
tax = taxcal(gross_pay);
net_pay = gross_pay - tax;
printf("Net Pay - %.2f", net_pay);
break;
case 3:
payrate = 22.40;
gross_pay = pay_cal(payrate, worked_hours);
tax = taxcal(gross_pay);
net_pay = gross_pay - tax;
printf("Net Pay - %.2f", net_pay);
break;
case 4:
payrate = 30.00;
gross_pay = pay_cal(payrate, worked_hours);
tax = taxcal(gross_pay);
net_pay = gross_pay - tax;
printf("Net Pay - %.2f", net_pay);
break;
*/
default :
printf("Please select the number from the menu [1-4]\n");
goto restart;
}
}
float pay_cal(float payrate, int worked_hours)
{
int normal_hours = 38;
float gross_pay;
float overtime_wage = 0.0;
if (worked_hours > normal_hours)
overtime_wage = (float)(worked_hours - normal_hours ) * payrate * 1.5;
gross_pay = (float)(worked_hours * payrate) + overtime_wage;
printf("\nGross Pay - %.2f", gross_pay);
return gross_pay;
}
float tax_cal(float gross_pay)
{
/*Tax rates: 15% of the first £300
20% of the next £200
25% of the next £150
30% of the rest
*/
float tax,tax1,tax2,tax3,tax4;
if(gross_pay <= 300.0 && gross_pay > 8.5)
{
tax = 0.15*gross_pay;
}
else if(gross_pay>=301.0 && gross_pay <= 500.0)
{
tax1 = 0.15 * 300.0;
tax2 = 0.2 * (gross_pay - 300.0);
tax = tax1 + tax2;
}
else if(gross_pay>=501.0 && gross_pay <= 650.0)
{
tax1 = 0.15 * 300.0;
tax2 = 0.2 * (500.0 - 300.0);
tax3 = 0.25 * (650.0 - 500.0);
tax = tax1 + tax2 + tax3;
}
else
{
tax1 = 0.15 * 300.0;
tax2 = 0.2 * (500.0 - 300.0);
tax3 = 0.25 * (650.0 - 500.0);
tax4 = 0.3 * (gross_pay - 650.0);
tax = tax1 + tax2 + tax3 + tax4;
}
printf("\nPayable Tax - %.2f", tax);
return tax;
}