if
if … else …
Simple Example
- Question
- Answer
Write a program to determine whether the body temperature entered by the user can be categorized as a fever
- Input: body temperature in celcius (C)
- Output: “Fever”, if body temperature is more than 37o C. If not, no outputs.
Relational Operators
Logical Operators
- Example
Chaining
Exercise
Exercise 1
- Question
- Answer
Write a program to calculate the total user must pay for an imported item.
- If the price of the item exceeds USD 100, then an import tax of 20% is imposed
- Input: price of items before tax in USD
- Output: total paid (item price plus tax)
Exercise 2
- Question
- Answer
Write a program to determine whether the value entered by the user is odd or even.
- Input: integer
- Output: “Odd” or “Even”
Exercise 3
- Question
- Answer
Write a program to determine whether the size of the baby at birth is normal or not
- Normal baby weight at birth ranges from 2.5 to 4.5 kg and lengths between 45 and 60 cm
- Input: baby’s weight in kg and length in cm
- Output: whether the baby’s size is normal or not
Exercise 4
- Question
- Answer
Write a program to convert grade in numbers to letters.
-
Conversion table:
- Input: grade in number
- Output: letter grade