CSIS 2610: Programming and Problem Solving 
Programming assignment 2: Branching Statements and Loops

Due 2/28

Objectives

This assignment will give you more practice with different types of branching statements, as well as an introduction to loops.

Requirements

You are to write a program that determines and prints a phone bill for a call. The bill depends on the following factors:

o       How many minutes long the call is.

o       The plan the customer is using. This will either be:

o       A flat rate

o       A business plan

o       A primetime rate plan

o       What time the call was made (if the customer is on the prime time plan).

These are used in the following rules:

FLAT RATE:

The cost of the call is 7 cents per minute.

BUSINESS PLAN:

The cost of a call is $1 for the first 10 minutes
                        and 2 cents for each additional minute over 10.

PRIMETIME RATE PLAN:

The cost of a call is:
            2 cents per minute if the call is before 9am.
            10 cents per minute if the call is between 9am and 5pm inclusive.
            5 cents per minute if the call is after 5pm.

User interface

As always, your input and output statements must be informative, explaining what is being prompted for/printed. You also have the following requirements:

o       You are to print a menu which lists the plans. The user should then enter a character (either F, B, or P) corresponding to their plan. For example:

F)lat rate plan
B)usiness plan
P)rimetime rate plan
Enter the letter (either F, B, or P) of your plan:

o       The time of the call should be entered as an hour in military time, between 0 and 23. For example, 9am is 9, and 5pm is 17.

Also note that you should not ask the user for the time of the call unless necessary (they are on the Primetime plan).

Input validation

Your program must also validate its input. Specifically, it must make sure that:

o       The user enters a positive number for the number of minutes.

o       The user enters a legal option for the rate plan.

o       The user enters a number between 0 and 23 for the time of the call.

If an input is not legal, your program must print an informative error message, and exit the program (as with the previous assignment, you may use the exit(0) function to do this).

Looping

Your program should also use a loop to compute as many bills as the user would like. After printing the bill, your code should prompt for whether the user wants to do another:

Do you want to compute another bill? (y or n):

If the user answers y, the program should loop back up to the beginning, asking for information and computing a bill again. Otherwise, the program should end.

Note that you should probably not start this until you have everything else working!

Design

As always, you should spend time designing your program (particularly it branching structure and conditions) before coding it. In this case, think about the following:

o       You should consider using a switch statement for handling menu choices.

o       You are to use nesting and/or logical operators where possible to simplify your code and make it more efficient.

Documentation

The program you turn in should be well documented. Along with everything else, make sure that your if statements are documented, describing what your condition represents, and what is being done down each branch.

In addition, make sure that your code is indented properly. This is an important part of your grade.

What to Turn In