I'm having problem with the while loop and switch statements. I can run case 1 all the way through, but when I input case 2 the program ends, what am I doing wrong? Please help.
Code:
#include <stdio.h>
void main(void)
{ int paycode, hours;
float hourly_rate, weekly_pay, weekly_salary, weekly_sales;
printf("Enter employee paycode (-1 to end): ");
scanf("%i", &paycode);
switch (paycode)
while (paycode = -1)
{
case 1:
printf(" Enter the weekly salary: ");
scanf("%i", &weekly_salary);
weekly_salary = 400;
printf("The employee's weekly pay is $ %6.2f\n\n", weekly_salary);
break;
case 2:
printf(" Enter the employee's hourly rate: ");
scanf("%f", &hourly_rate);
printf(" Enter the hours worked: ");
scanf("%i", &hours);
if(hours <= 40)
{
weekly_pay = hourly_rate * hours;
printf("The employee's weekly pay is $ %6.2f\n\n", weekly_pay);
}
else if(hours > 40)
{
weekly_pay = (hourly_rate * 40) + ((1.5 * 12.50) * 5);
printf("The employee's weekly pay is $ %6.2f\n\n", weekly_pay);
}
break;
case 3:
printf(" Enter the gross weekly sales: ");
scanf("%i", &weekly_sales);
weekly_sales = 250 + (1000 * .057);
printf("The employee's weekly pay is $ %6.2f\n\n", weekly_sales);
break;
}
printf("Enter employee paycode (-1 to end): ");
scanf("%i", &paycode);
}