CSE110 Summer Session I

Homework #3: Control Flow and Derived Types

Due Friday, June 8 2001

NOTE: Please remember to provide relevant comments on all programs
Also, name your files hw3p1.c, hw3p2.c, hw3p3.c

Further demonstrations of the desired output are available by running the following files:
/html/courses/cse110/hw3p1
/html/courses/cse110/hw3p2
/html/courses/cse110/hw3p3


1. [50 points] It's lunch time! For this problem, you will write a program to simulate the operations of a food truck. The following food items will be sold at your food truck:

cheesesteak   $3.25
turkey hoagie $3.00
potato chips  $0.50
banana        $0.25
soda          $1.00
lemonade      $1.25
The customer should be given a menu with these choices plus a "done purchasing" option. After selecting an item, the customer is asked how many of that item he would like. The customer can continue selecting items from the menu until he indicates he is finished by selecting the done purchasing option. At this time, the customer is told the total cost of his lunch and is prompted for payment. After entering a payment amount, the customer receives change if any.

A few things to note:

Some special rules:

% a.out
Welcome to the LunchExpress food truck!

*************************
*  C  Cheesesteak       *
*  T  Turkey Hoagie     *
*  P  Potato Chips      *
*  B  Banana            *
*  S  Soda              *
*  L  Lemondade         *
*                       *
*  D  Done Purchasing   *
*************************

What would you like? c
How many? 1

*************************
*  C  Cheesesteak       *
*  T  Turkey Hoagie     *
*  P  Potato Chips      *
*  B  Banana            *
*  S  Soda              *
*  L  Lemondade         *
*                       *
*  D  Done Purchasing   *
*************************

What would you like? P
How many? 2

*************************
*  C  Cheesesteak       *
*  T  Turkey Hoagie     *
*  P  Potato Chips      *
*  B  Banana            *
*  S  Soda              *
*  L  Lemondade         *
*                       *
*  D  Done Purchasing   *
*************************

What would you like? soda
How many? 1

*************************
*  C  Cheesesteak       *
*  T  Turkey Hoagie     *
*  P  Potato Chips      *
*  B  Banana            *
*  S  Soda              *
*  L  Lemondade         *
*                       *
*  D  Done Purchasing   *
*************************

What would you like? q
That is not a valid menu item!

*************************
*  C  Cheesesteak       *
*  T  Turkey Hoagie     *
*  P  Potato Chips      *
*  B  Banana            *
*  S  Soda              *
*  L  Lemondade         *
*                       *
*  D  Done Purchasing   *
*************************

What would you like? d

Your total comes to $5.25
Please enter your payment amount: 5.00
That is not enough, you still owe $0.25
Please enter more money: 1.00
Your change is $0.75
Please come again!


2. [25 Points] Modify your program from problem 1 by replacing the cascading if statement with a switch statement. You can still have nested if statements in the switch. (Note: We haven't covered switch statements yet (as of 6/1). We will go over them on Monday or Tuesday.)


3. [25 Points] Modify either the program from problem 1 or 2 so that the menu uses numbers instead of characters to select items. This must be done using an enumerated type. Define an enumerated type called menuItem with the following members: CHEESESTEAK, TURKEY_HOAGIE, POTATO_CHIPS, BANANA, SODA, LEMONADE, and DONE_PURCHASING. Use these members within the case/if statements. For example: if (item == CHEESESTEAK) NOT if (item == 1).

% a.out
Welcome to the LunchExpress food truck!

*************************
*  1  Cheesesteak       *
*  2  Turkey Hoagie     *
*  3  Potato Chips      *
*  4  Banana            *
*  5  Soda              *
*  6  Lemondade         *
*                       *
*  7  Done Purchasing   *
*************************

What would you like? 0
That is not a valid menu item!

*************************
*  1  Cheesesteak       *
*  2  Turkey Hoagie     *
*  3  Potato Chips      *
*  4  Banana            *
*  5  Soda              *
*  6  Lemondade         *
*                       *
*  7  Done Purchasing   *
*************************

What would you like? 2
How many? 2

*************************
*  1  Cheesesteak       *
*  2  Turkey Hoagie     *
*  3  Potato Chips      *
*  4  Banana            *
*  5  Soda              *
*  6  Lemondade         *
*                       *
*  7  Done Purchasing   *
*************************

What would you like? 7

Your total comes to $6.00
Please enter your payment amount: 10.00
Your change is $4.00
Please come again!