You are on page 1of 1

Fundamentals of programming

Lab task#3

Question 1:
Write a program to get input a number (i.e. is your age) form keyboard and check it.

Condition Message
age is less than 50 "You are pretty young!"
age is equal to 50 "You are old"
age is greater than 50 "You are really old"

Question 2:

Write if statements to do the following:


 If integer variable test is even or odd.

 If integer variable opCode has the value 1, read in or input double values for X and Y and
calculate and print their sum.

 If integer variable currentNumber is odd, change its value so that it is now 3


times currentNumber plus 1, otherwise change its value so that it is now half of
currentNumber

 If integer variable Number is multiple of 3 or not

 Assign a value to double variable cost depending on the value of integer variable
distance as follows:
Distance Cost
----------------------------------- ------------------
0 through 100 5.00
More than 100 but not more than 500 8.00
More than 500 but less than 1,000 10.00
1,000 or more 12.00

Question 3:

What is wrong with the following if statement (there are at least 3 errors). The indentation
indicates the desired behavior. (Check it either manually or by writing the whole code in a C++
source file in a complete C++ program)

if numNeighbors >= 3 || numNeighbors = 4


++numNeighbors;
cout << "You are dead!" << endl;
else
--numNeighbors;

You might also like