# Practical 02: Selection Statements

We will now proceed with implementing selection statements in this practical. Selection statements in C include the if-else statement and the switch statement.

# Getting Started

# Tasks

# Task 1

Write a program that prompts the user to enter two double values. The program should then compare the two numbers to see if they are equal, or whether one is larger than the other. You are required to use the single-selection form of the if statement for this task.

# Task 2

Write a program that prompts the user to input three different integer values. The program should then print the sum, average and product of these three values, as well as the smallest and largest amongst these values. You are required to use the single-selection form of the if statement for this task.

# Task 3

A program is required to calculate the weekly pay for an employee. The pay clerk inputs an employee ID, hours worked on and an hourly rate. The program will output the employee ID and a calculated gross pay amount. The gross pay is essentially the total amount between the regular pay and overtime pay earned. The overtime pay is paid at 1.5 times the pay rate for any hours worked over 40.

The sample outputs are as follows:

Enter employee ID >> E12333
Enter hours worked >> 30
Enter hourly rate >> 20
==============================
Employee ID: E12333
Hours Worked: 30.00
Hourly Rate: $20.00
Gross Pay: $600.00
1
2
3
4
5
6
7
8
Enter employee ID >> EMP003
Enter hours worked >> 60
Enter hourly rate >> 20
==============================
Employee ID: EMP003
Hours Worked: 60.00
Hourly Rate: $20.00
Gross Pay: $1400.00
1
2
3
4
5
6
7
8

# Task 4

Write a program that reads three non-zero integers and determines whether they can be the sides of a right triangle.

# Task 5

A palindrome is a number or a text phrase that reads the same backwards as forwards. For instance, each of the following five-digit integers is a palindrome: 12321, 55555, 45554, 11611.

Write a program that reads a 5-digit integer and determines whether or not it is a palindrome.

TIP

Use the division and modulo operators to separate the number into its individual digits.

Last Updated: 5/17/2022, 10:12:37 PM