hw6_main.cpp
/*
Programmer: Jennifer Leopold
Date: October 5, 2016
File: hw6_main.cpp
Purpose: Simulate a snarky vending machine that dispenses
homeopathic remedies/supplements.
To compile: fg++ hw6_main.cpp hw6_functs.cpp -o hw6
To execute: ./hw6
*/
#include <iostream>
#include <cstdlib>
#include <ctime>
#include "hw6_functs.h"
using namespace std;
int main()
{
srand(time(NULL)); // seed random # generator
string customerName; // customer's name
float total = 0; // customer's total charges
int numMenu1 = MENU_ITEM_1_QTY; // qty of each menu item
int numMenu2 = MENU_ITEM_2_QTY;
int numMenu3 = MENU_ITEM_3_QTY;
int numMenu4 = MENU_ITEM_4_QTY;
int numMenu5 = MENU_ITEM_5_QTY;
short menuChoice; // menu selection
short quantity; // qty of selected item
bool isTimeToQuit = false; // true when purchases
// completed
// Set precision to 2 decimal places for dollar amount output
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
// Greet user and get his/her name
customerName = greetUser();
// Let user repeatedly make selections from the menu
// until s/he chooses to 'quit'
do
{
// Make a selection from menu
displayMenu(numMenu1, numMenu2, numMenu3, numMenu4,
numMenu5);
menuChoice = getMenuSelection();
// Update customer's running total and item inventory
switch (menuChoice)
{
case 1: quantity = getQuantityInput(numMenu1, MENU_ITEM_1);
total += quantity * MENU_ITEM_1_PRICE;
numMenu1 -= quantity;
break;
case 2: quantity = getQuantityInput(numMenu2, MENU_ITEM_2);
total += quantity * MENU_ITEM_2_PRICE;
numMenu2 -= quantity;
break;
case 3: quantity = getQuantityInput(numMenu3, MENU_ITEM_3);
total += quantity * MENU_ITEM_3_PRICE;
numMenu3 -= quantity;
break;
case 4: quantity = getQuantityInput(numMenu4, MENU_ITEM_4);
total += quantity * MENU_ITEM_4_PRICE;
numMenu4 -= quantity;
break;
case 5: quantity = getQuantityInput(numMenu5, MENU_ITEM_5);
total += quantity * MENU_ITEM_5_PRICE;
numMenu5 -= quantity;
break;
case 6: isTimeToQuit= true;
}
} while (! isTimeToQuit);
// Figure in tax and make user pay
if (total > 0)
{
// Add tax to current total
applyTax(total);
// Get user's payment and output change
getPaid(total, customerName);
}
// Sign off
signOff(customerName);
return 0;
}