Solution

// programmer: Clayton Price

// file: hw4.cpp class: cs 1570

// purpose: this file contains the main function for the program that will vend

// body parts for Dr. Nick.

#include <iostream>

using namespace std;

int main()

{

/* ---------------------------- DECLARATIONS ------------------ */

const string ITEM1 = "Eyeballs"; // these constants are for the items

const string ITEM2 = "Spleen"; // in the vending machine and match

const string ITEM3 = "Liver"; // with the constants below too

const string ITEM4 = "Appendix";

const string ITEM5 = "Brains";

const string ITEM6 = "Ear Lobes";

const float ITEM1_PRICE = 3.35; // prices of the items above

const float ITEM2_PRICE = 2.75;

const float ITEM3_PRICE = 14.58;

const float ITEM4_PRICE = .5;

const float ITEM5_PRICE = 7.85;

const float ITEM6_PRICE = 13.45;

const float ITEM1_WT = .4; // wts of the items above

const float ITEM2_WT = 5.6;

const float ITEM3_WT = 3;

const float ITEM4_WT = 1.2;

const float ITEM5_WT = 2.3;

const float ITEM6_WT = 10;

const int PAN1 = 1; // standard pan sizes

const int PAN2 = 2;

const int PAN3 = 5;

const int PAN4 = 10;

const int PAN5 = 15;

char choice; // user input

float price; // price of item chosen

float wt; // wt of item chosen

float change; // change to customer

float user_deposit; // user proferred money

float pan; // temp value

bool quit = false;

bool valid_choice_made = false;

cout.setf(ios::showpoint);

cout.setf(ios::fixed);

cout.precision(2);

/* --------------- PROMPTS, GREETINGS, FIGURING ----------- */

cout<<"\n\n\nWelcome to Dr. Nick's ORGAN-O-MATIC!"<<endl<<endl;

do

{

valid_choice_made = false;

cout<<"\t\tPLEASE PICK YOUR BEST"<<endl<<endl

<<"\t1. "<<ITEM1<<endl

<<"\t2. "<<ITEM2<<endl

<<"\t3. "<<ITEM3<<endl

<<"\t4. "<<ITEM4<<endl

<<"\t5. "<<ITEM5<<endl

<<"\t6. "<<ITEM6<<endl

<<"\t7. Quit"<<endl<<endl

<<"What is your choice? ";

cin>>choice;

switch (choice)

{

case '1':

cout<<"\n\nHere's your "<<ITEM1<<endl;

price = ITEM1_PRICE;

wt = ITEM1_WT;

valid_choice_made = true;

break;

case '2':

cout<<"\n\nHere's your "<<ITEM2<<endl;

price = ITEM2_PRICE;

wt = ITEM2_WT;

valid_choice_made = true;

break;

case '3':

cout<<"\n\nHere's your "<<ITEM3<<endl;

price = ITEM3_PRICE;

wt = ITEM3_WT;

valid_choice_made = true;

break;

case '4':

cout<<"\n\nHere's your "<<ITEM4<<endl;

price = ITEM4_PRICE;

wt = ITEM4_WT;

valid_choice_made = true;

// break; BREAKS REMOVED TO SIMULATE BROKEN MACHINE

case '5':

cout<<"\n\nHere's your "<<ITEM5<<endl;

price = ITEM5_PRICE;

wt = ITEM5_WT;

valid_choice_made = true;

// break;

case '6':

cout<<"\n\nHere's your "<<ITEM6<<endl;

price = ITEM6_PRICE;

wt = ITEM6_WT;

valid_choice_made = true;

break;

case '7':

quit = true;

break;

default:

cout<<"\n\tInvalid entry. Please try again"<<endl<<endl;

}

if (valid_choice_made) // calculate and output only if non quit choice

{

do

{

cout<<"\n\n\tThe price of your choice is $"<<price<<endl

<<"\n\tPlease deposit that much $";

cin>>user_deposit;

if (user_deposit < price)

cout<<"\n\t\tINSUFFICIENT FUNDS!....."<<endl;

} while (user_deposit < price);

if (user_deposit > price)

{

change = user_deposit - price;

cout<<"\n\t\tYour change is $"<<change<<endl<<endl;

}

if (wt > PAN4)

cout<<"LOOK OUT! WHAT'S COMING IS TOO BIG FOR ANY STANDARD PAN!"<<endl;

else

{

if (wt > PAN4)

pan = PAN5;

else if (wt > PAN3)

pan = PAN4;

else if (wt > PAN2)

pan = PAN3;

else if (wt > PAN1)

pan = PAN2;

else pan = PAN1;

cout.precision(0);

cout.unsetf(ios::showpoint);

cout<<"\n\tYour organ weighs "<<wt<<" lbs, so you will need a "

<<pan<<" lb pan"<<endl;

cout.precision(2);

cout.setf(ios::showpoint);

cout<<"\n\t\tTHANKS!....and enjoy your oragan(s)!!"<<endl;

}

}

} while (!quit);

cout<<"\n\n\tHope you enjoy our products...and the surgery goes well!"

<<endl;

return 0;

}