Hi, i have a little problem. I want this program to continue to ask the user how much is their hourly worked, until the user enters -1, this will end the program. Can any one give me some hints in how to do this.
Code:
#include<stdio.h>
main()
{
float hours_worked, hourly_rate, salary, overtime_hours, overtime_salary, times_half, total_salary;
printf("Enter hours worked(-1 to end): ");
scanf("%f",&hours_worked); //stores variable hours_worked
printf("Enter hourly rate of the worker ($00.00): ");
scanf("%f",&hourly_rate); //stores variable hourly_rate
if (hours_worked<=40)
{
salary= hours_worked*hourly_rate; // multiplication to get variable salary
printf("Salary is $%0.2f", salary);
}
else if (hours_worked>=41)
{
overtime_hours =hours_worked-40; // calculations for overtime_salary
salary =40*hourly_rate;
times_half =overtime_hours*hourly_rate/2;
overtime_salary =times_half+hourly_rate;
total_salary =salary+overtime_salary;
printf("Employee worked %3.0f hour(s) overtime for a value of $%0.2f\n", overtime_hours, overtime_salary);
printf("Salary is $%0.2f", total_salary);
}
//else if(hours_worked==-1) // i need to have something here when the there is -1 the program will end
return 0;
}