Practice Ercise: Control Structures--Limit and Range tests
Objective:
Be able to employ the if, if..else, if..else..if
The general form for the if statement is:
if (expression)
statement ...;
else ...;
Compound statement blocks are surrounded by {}.
1. Given that a variable named creditHours has a value less than 30 assign to
classYear the value "freshman".
2. When the value of a variable named creditHours is in the range from 30 to 59
(inclusive), assign to classYear the value "sophomore".
3. Determine academic classification based upon credit hours accumulated. When
the value of creditHours is greater than or equal to 90, assign to classYear
the string value "Senior"; when creditHours range from 60 through 89
(inclusive), assign to classYear the value 'Junior'; when creditHours range
from 30 through 59 assign to classYear the value "Sophomore"; and when
creditHours are less than 30 assign "Freshman".
4. Compute cafeteria meal charges according to the following rules: For a
semester meal count less than 25, per meal charge is $7.00; meal count in
the range 26 through 50, per meal charge is $6.00, and for over 50 meals
per semester the per meal charge is $5.00. Input the meal count, determine
per meal charge, then compute and output the total meal charge.