Lab 4 - Nested If-else statements
This lab gives you practice on writing branching programs in C. The
following problems would require using conditional statements such as
if-else statements as discussed in class. If you missed the class, review
the slides and video posted for Lecture 3 and 4 to familiarize yourself
with conditional statements.
1 Problems
Please submit ONE of these problems based on your student number.
You can do both if you like (practice makes perfect!) but only one will
be marked.
1.1 Problem a - Student Number is ODD
A hurricane is a strong storm that is designated to a category based
on its maximum sustained wind speed as shown in the table below.
Sustained Wind Speed Hurricane Designation Table 1: Hurricane designation based on
sustained maximum wind speed.
119 − 153 km/h Category 1
>153 km/h to 177 km/h Category 2
>177 km/h to 208 km/h Category 3
>208 km/h to 251 km/h Category 4
>251 km/h Category 5
We like to write a program that prompts the user for the sustained
wind speed of a hurricane and then prints out the category of the
hurricane. Here are some sample runs of the program:
Enter the sustained wind speed of the hurricane: 122
This is a Category 1 hurricane.
Enter the sustained wind speed of the hurricane: 100
This is not a hurricane.
Enter the sustained wind speed of the hurricane: -10
Hurricane speed cannot be negative.
Make sure that you also handle the situation when the user enters
a wind speed that does not fit the above list1 1
For example, if the wind speed is be-
low 119 km/hr or the number entered is
negative.
1.2 Problem b Student Number is EVEN
A company that allows individuals or companies to buy stock of pub-
lic companies is called a broker. Brokers charge a fee or commission for
lab 4 - nested if-else statements 2
trading2 based on the number of shares that a client trades. Assume 2
trading means buying or selling stocks
that a certain company has the following fee structure. of public companies
Number of Shares Traded Commission Table 2: Commission structure
<=1000 $29.95
1001 − 4000 $0.03/share
4001 − 10000 $0.02/share
>10000 $0.01/share
Write a program that will accept as input the number of shares that
a client wants to buy or sell and then prints out the commission. A
sample output is shown below:
Enter the number of shares you would like to trade: 1500
Your commission would be $45.00
Enter the number of shares you would like to trade: 900
Your commission would be $29.95
Enter the number of shares you would like to trade: -1000
Number of shares must be larger than 0.
Enter the number of shares you would like to trade: 0
Number of shares must be larger than 0.
Make sure that you also gracefully handle the situation when the
user enters a number of shares that is nonsensical3 3
For example, when number of shares
entered is negative.
2 Deliverables
As always, please submit your .c file (not any other file!) with the
naming convention FirstNameLastName_Lab04.c
Your code must be your own work. You can discuss how to solve
the problem, but you must write your code yourself without looking
at anyone else’s code