/* hw3p3.c 
   lunch truck problem with switch and enumerated type
*/


#include <stdio.h>
#include "simpio.h"

#define COST_CHEESESTEAK     3.25
#define COST_TURKEY_HOAGIE  3.00
#define COST_POTATO_CHIPS    .50
#define COST_BANANA          .25
#define COST_SODA           1.00
#define COST_LEMONADE       1.25

typedef enum {
  CHEESESTEAK = 1, TURKEY_HOAGIE, POTATO_CHIPS, BANANA, SODA, 
  LEMONADE, DONE_PURCHASING
} menuItem;

void main()
{
  menuItem item;
  double cheesesteak = 0, turkey_hoagie = 0, potato_chips = 0, banana = 0, 
    soda = 0, lemonade = 0, total, owe, pay;
  int qty, done = 0;

  printf("Welcome to the LunchExpress food truck!\n");

  while (!done) {
    printf("\n*************************\n");
    printf("*  1  Cheesesteak       *\n");
    printf("*  2  Turkey Hoagie     *\n");
    printf("*  3  Potato Chips      *\n");
    printf("*  4  Banana            *\n");
    printf("*  5  Soda              *\n");
    printf("*  6  Lemondade         *\n");
    printf("*                       *\n");
    printf("*  7  Done Purchasing   *\n");
    printf("*************************\n");

    printf("\nWhat would you like? ");
    item = GetInteger();

    if (item >= 1 && item <= 6) {
      /* prompt for quantity */
      printf("How many? ");
      qty = GetInteger();
    }

    /* switch statement uses item, which is an integer, but should be
       referenced using the possible values for the enumerated type
       menuItem
    */
    switch (item) {
    case CHEESESTEAK:
      cheesesteak = COST_CHEESESTEAK * qty;
      break;
    case TURKEY_HOAGIE:
      turkey_hoagie = COST_TURKEY_HOAGIE * qty;
      break;
    case POTATO_CHIPS:
      potato_chips = COST_POTATO_CHIPS * qty;
      break;
    case BANANA:
      banana = COST_BANANA * qty;
      break;
    case SODA:
      soda = COST_SODA * qty;
      break;
    case LEMONADE:
      lemonade = COST_LEMONADE * qty;
      break;
    case DONE_PURCHASING:
      done = 1;
      break;
    default:
      /* invalid selection */
      printf("That is not a valid menu item!\n");
      break;
    }
  }

  total = cheesesteak + turkey_hoagie + potato_chips + banana + 
    soda + lemonade;
  printf("Your total comes to $%.2f\n", total);
  printf("Please enter your payment amount: ");
  pay = GetReal();
  owe = total - pay;
  while (owe > 0) {
    printf("That is not enough, you still owe $%.2f\n", owe);
    printf("Please enter more money: ");
    pay += GetReal();
    owe = total - pay;
  }
  printf("Your change is $%.2f\n", pay - total);
  printf("Please come again!\n");
}
