Selection Program Structure
Selection Program Structure
Syntax 1. if condition
Page 1 of 7
Computer Fundamentals
In a multiway if-else condition, if the first if condition is TRUE it will execute the
statement/s for that condition and it will check the other if condition in the list.
On the other hand, if no if condition is satisfied it will execute the statement of the
last else in the list.
Page 2 of 7
Computer Fundamentals
:
:
Page 3 of 7
Computer Fundamentals
1.) Create a flowchart and a C++ program that will prompt the user to input two
numbers and output the highest number entered.
Stop
Page 4 of 7
Computer Fundamentals
2.) Create a flowchart and a C++ program that would input an integer number and then
indicate whether the number is an even or an odd number.
Flowchart
Start
Declarations
num number
Input number
If Y Output
number % 2 == 0 A
“even number”
N
Output
“odd number”
A
Stop
C++ Program
#include<iostream>
using namespace std;
int main()
{ int num
if (num % 2 == 0)
cout<< “ The number you’ve entered is an even number”<<endl;
else
cout<< “ The number you’ve entered is an odd number”<<endl;
return 0;
}
Page 5 of 7
Computer Fundamentals
3.) Workers at Kookaburra Factory have a regular working hours of 30 hours per week
and are paid $ 10.00 per hour. However, if the workers rendered more than 30 hours
per week, the excess hours are paid 75% more. Create a flowchart and a C++ program
that would input the number of hours rendered by a worker in one week and output his
net salary.
Flowchart
Start
Declarations
NHrs, Salary
Input NHrs
If N
Salary = NHrs *10 A
NHrs > 30
Y
Salary = 300 + (NHrs – 30) * 17.50
A
Output Salary
Stop
C++ Program
#include <iostream>
using namespace std;
int main()
{ double NHrs, Salary;
4.) The fine for an over-speeding violation depends on the speed of the erring driver, as
follows:
100 to 120 km/h = 3,000.00 Php
121 km/h and above = 5, 000 Php
Create a flowchart and a C++ program to input the car’s speed and then output the
fine, if there’s any.
5.) In the game of JACK N POY each of the two player choose either a scissors (code S),
paper (code P), or rock (code R). If one chooses scissors and the other chooses stone
then stone wins. If one chooses paper and the other stone then paper wins. If one chooses
paper and the other scissors then scissors wins. If they both choose the same then the
result is a tie. Create a flowchart or a C++ program that will input two character codes
corresponding to the object selected and then output either the message “PLAYER 1
WINS” or “PLAYER 2 WINS”.
Page 7 of 7