forked from joe59105/Group-11-C-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
3_20_Salary_Calculator.c
52 lines (40 loc) · 1.4 KB
/
3_20_Salary_Calculator.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <stdio.h>
int main()
{
// variable declarations
int hoursWorked = 0;
int overtimeHours = 0;
float hourlyRate = 0;
float overtimeRate = 0;
float overtimePay = 0;
float salary = 0;
while (hoursWorked != -1)
{
salary = 0; // clear the salary variable of former data
printf("%s", "Enter # of hours worked (-1 to end): ");
scanf("%d", &hoursWorked);
if (hoursWorked == -1)
{
// User wants to exit the program
printf("Thank you for using our Salary Calculator");
return 0;
}
printf("%s", "Enter hourly rate of the worker ($00.00): ");
scanf("%f", &hourlyRate);
if (hoursWorked <= 40)
{
salary = (hoursWorked * hourlyRate);
}
else if (hoursWorked > 40)
{
salary = (40 * hourlyRate); // Pay the straight rate for the 40 hours
overtimeHours = hoursWorked - 40; // Calculate the extra hours the worker worked
overtimeRate = 1.5 * hourlyRate; // Calculate the rate for the new hours - "time and a half"
overtimePay = overtimeHours * overtimeRate; // calculate the extra money earned
salary = salary + overtimePay; // add regular and overtime pay together
}
// display salary
printf("Salary is $%.2f", salary);
printf("%s", "\n\n");
}
}