You are on page 1of 8

EXAMPLE USING IF-ELSEIF-ELSE

STATEMENT
• C++ Program to Check Whether a character if it
is a Vowel or a Consonant.
• In this example, if...else statement is used to
check whether an alphabet entered by the user
is a vowel or a constant.
The isalpha() function
checks whether the
character entered is an
alphabet or not. If it is
not, it prints an error
message.
EXAMPLE
• Suppose savings and expenses are variables of type
double that have been given values. Write an if-else
statement that outputs the word Solvent, decreases
the value of savings by the value of expenses, and
sets the value of expenses to 0, provided that
savings is at least as large as expenses. If, however,
savings is less than expenses, the if-else statement
simply outputs the word Bankrupt and does not
change the value of any variables
• cout.setf(ios::fixed) makes cout print floats with a fixed
number of decimals

• cout.setf(ios::showpoint); - display decimal point and


trailing zeros for all floating point numbers, even if the
decimal places are not needed.

You might also like