Specification of An Action Operators Operands Operands Unary Binary Ternary Block
Specification of An Action Operators Operands Operands Unary Binary Ternary Block
Specification of An Action Operators Operands Operands Unary Binary Ternary Block
3. Write a C program to calculate employee weekly pay. The program is required to read
the employee name, his total number of regular hours worked, total overtime hours and
hourly wage rate. Weekly pay is calculated as payment for regular hours worked, plus
payment for overtime hours worked. Payment for regular hours worked is calculated as
(wage rate times regular hours worked); payment for overtime hours worked is
calculated as (wage rate times overtime hours worked times 1.5). Display the employee
name and his weekly pay on the screen.
#include <stdio.h>
int main()
{
//to store string, need to use array consept
char name[100];
float regularHours, overtimeHours, wageRate, regularPay, overtimePay, totalPay;
// Read inputs
printf("Enter employee name: ");
scanf("%s", name);
// or fgets(name,100,stdin) --> similar to scanf(but this will read space)
// stdin= standard input that comes with the function, user input
// means I create a array named "name" that can store 100 characters
printf("Enter total regular hours worked: ");
scanf("%f", ®ularHours);
printf("Enter total overtime hours worked: ");
scanf("%f", &overtimeHours);
printf("Enter hourly wage rate: ");
scanf("%f", &wageRate);
// Calculate pay
regularPay = wageRate * regularHours;
overtimePay = wageRate * overtimeHours * 1.5;
totalPay = regularPay + overtimePay;
// Display output
printf("Employee name: %s\n", name);
printf("Weekly pay: $%.2f\n", totalPay);
return 0;
}