LAB 9 C++ Part 2
LAB 9 C++ Part 2
9: C++
programming
1- MAKING DECISIONS
The if-else statement provides the capability of making decisions. The general format of the if-
else statement is:
If (expression)
{
Statements
}
else
{
Statements
If expression is true, then the program will execute statements between the curly brackets that
follow if. Otherwise, the program will execute statements between the curly brackets that follow
else.
In C++ we use the following operators to formulate conditions and logical expressions:
#include <iostream>
int main()
{
int value;
cout<<"Please enter a value: "<<endl;
cin>>value;
if (value == 0)
{
cout<<"The value was 0\n"<<endl;
cout<<"Thank you for your input\n"<<endl;
} else
{
Page 1 of 2
Computing Fundamentals CS1150 ______ Lab NO. 9: C++ programmin
return 0;
}
Write a program that reads two numbers a and b. Print the maximum value of the two numbers.
Write a program that reads two values a and b. If b is 0, output “b is 0”. Otherwise output the result
of the division of a by b (a / b).
Write a program that reads three numbers a, b, and c. Print the maximum value of the three numbers.
[90 – 100] : A
[80 – 90 ] : B
[70 – 80 ] : C
[60 – 70 ] : D
[50 – 60 ] : E
[0 – 50 ] : F
Page 2 of 2