You are on page 1of 2

CSC128

LAB EXERCISE 2 SELECTION

ONE-WAY SELECTION if (without else)

1. Write a program to check whether a number input by user is a positive number. If


positive, display an appropriate message.

2. Write a program to check whether a number input by user is odd number. If odd,
display an appropriate message.

3. Write a program to check whether a number input by user is even number. If even,
display an appropriate message.

4. Write a program to check whether a number input by user is positive number. If


positive, multiply that number with 10 and display it.

5. Write a program to input price and quantity of the item. Calculate the total price for all
items. If total price is greater than RM50, give 15% discount to customer. Display the
price before and after discount.

TWO-WAY SELECTION if…else

1. Write a program to check whether a number input by user is positive or negative


number. If positive, display “positive”, and otherwise display “negative”.

2. Write a program to check whether a number input by user is odd or even number. If
odd, display “odd”, otherwise display “even”.

3. Write a program to check whether a grade input by user is fail or not. If grade is less
than to 50, display “fail”, and otherwise display “pass”.

4. Write program to input a number. Check whether a number can be divisible by 5. If


yes, sum that number with 10, otherwise multiply that number with 2. Display that
number after the process.

5. Write a program to input price and quantity of item. Calculate the total price for all
items. If total price is greater than RM50, give 20% discount to customer. If not, give
5% discount to customer.

Display the price before and after discount.

6. You are given the following requirements:

a. Your program should read two inputs from the keyboard, which are the
amount of investment and profit.

b. If the investment is more than or equal to RM50,000 and the profit is more
than RM20,000, the following message is displayed: This investment is
worthy to continue

c. Otherwise displays the following message: This investment is a waste of


money.

Write a program based on the above requirements.

NORMAZIAH - FSKM
CSC128

MULTIPLE SELECTION

1. PWM Bank wants to do a program so that it can help the customer to calculate the
monthly instalment. The program will receive two inputs from the customer which are
the amount of loan in Ringgit Malaysia and year of instalment. Based on those
two inputs, write a program to calculate and display the monthly instalment.
The table of interest calculation is provided as follows:

Condition (year) Interest(%)


Above 10 years 3.6
5<=year<=10 3.25
1<=year<5` 2.88

Interest (RM) = interest(%) * Amount of loan


Total loan with interest = Amount of loan + Interest (RM)
Monthly Instalment = Total loan with interest / (year of instalment *12)

2. Write a C++ program that will accept two numbers that are greater than zero.
If user enter s number less than or equal to zero, display an error message.
Otherwise user need to input an arithmetic operator(+,-,*,/). The program will
perform calculation on those number using operator and display the result.

Enter two positive numbers: 5 10


Enter arithmetic operator(+,-,*,/) : *

5 * 10 = 50

NORMAZIAH - FSKM

You might also like