Title: Multiple Selections!!! NESTED IF
1Multiple Selections!!! NESTED IF
What if I have multiple selections!!! Look at the
syntax below if (condition) if
(condition) else else if
(condition) else
Lets do Example alphaone
2Multiple Selections SWITCH CASE
Wooffff!!! That previous problem was a bit
confusing!!! So theres another way!!!! switch
(expression) case value1 statement1 break ca
se value2 statement 2 break .. .. default
statements So when do I use SWITCH and when
do I use IFELSE Notice in SWITCH ? expression is
not a logical condition Notice in IF ? condition
is a logical Lets do example alphatwo
3FUNCTIONS
Int main() coutltlthello coutltlthi coutltlthow
coutltltare coutltltyou? coutltlthello cout
ltlthi coutltlthow coutltltare coutltltyou?
Int main() testfunction() Int
testfunction() coutltlthello coutltlthi coutltlt
how coutltltare coutltltyou?
Which is better??? You decide????
4Value Returning functions
Functions
VOID functions
Order of the three parts FUNCTION Header Int
main() .. Function call .. Function()
- A function contains the following
- A function header
- A function call
- The function..
VOID FUNCTIONS
Has no return value. Its all in the example
1.Lets do it A new hello world program.
5Question Write a function called ADD. It takes
the input of two numbers and Adds them. Print
the result.
Value Returning Functions
General syntax FunctionType functionName
(formal parameters) Statements Return
? Formal paramenter ? dataType identifier,
dataType identifier,.
6Function call
functionName (actual parameter list) Actual
parameter ? variable, variable,. EXAMPLE
3 Question Write a Program that takes the input
of three numbers and Write a function that finds
the largest of the three numbers. The function
Should take the three numbers as parameters and
return the largest of the Three numbers