Specification of An Action Operators Operands Operands Unary Binary Ternary Block

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Lab 5

1. Fill in the blank.


a) Statement is a _specification of an action_to be taken by the computer as the
program executes.
b) An Expression is a Combination of both _operators_and_operands_.
c) Operators act on_operands_.
d) Operators are divided into_unary_, binary and _ternary_.
e) Several statements grouped together in braces ({ and }) are called a(n)_block_.

2. Give an example of Arithmetic Operator, Relational Operator and Logical Operator.


Arithmetic Operator: +(addition)
Relational Operator: >(greater than)
Logical Operator: || (OR)

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", &regularHours);
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;
}

You might also like