Solution

/ Programmer: Clayton Price date: 9/17/13 // File: MoesBar.cpp class: cs 53 // Purpose: This file contains the main function for the vetting machine for // Moe's bar. #include <iostream> using namespace std; int main() { /* ---------------------- declarations ------------------ */ const string FAVORITE_CUSTOMER = "Barney"; const float BEER_PRICE = 2.00; const float HARD_LIQUOR_PRICE = 4.25; const short MIN_WALKING_AGE = 3; const short MAX_AGE = 120; const short DRINKING_AGE = 21; const string BAR_OWNERS_NAME = "Moe Syzlak"; const string KICKED_OUT = " Get outta heya, ya scum!! "; short cust_age; short num_drinks; short num_drinks_can_buy; float pocket_money; string name; // customer's name char tt_response; // tea-totaller response char another_customer; char drink_type; bool kickedOut = false; /* -------------- welcomes / greetings / name ----------- */ cout<<"\n\n\tWelcome to Moe's bar!" <<"\n\t\t"<<BAR_OWNERS_NAME<<", proprietor"<<endl<<endl; do { kickedOut = false; cout<<"Whutz ya name? "; cin>>name; if (name == FAVORITE_CUSTOMER)

cout<<"C'mon in "<<FAVORITE_CUSTOMER<<endl;

else

{

do // tea-totaller or not { cout<<"Ok, "<<name<<", say, are youz a, ya know, a tee-totalluh(y/n)? "; cin>>tt_response; } while (tt_response != 'y' && tt_response != 'n'); if (tt_response == 'y') // vett the tt's { cout<<"You aint gunna buy no drinks!"; // kick them out kickedOut = true; } else // accept non-tt's { do // looking for reasonable { // age cout<<"Sooo, how old ar yuz? "; cin>>cust_age; } while (MIN_WALKING_AGE > cust_age || cust_age > MAX_AGE); if (cust_age < DRINKING_AGE) { cout<<"\nHeyy, youz too young ta drink!"; kickedOut = true; } else // old enough to drink { do { cout<<"What ya drinkin'?"<<endl; cout<<"\tBeer (b)\n" <<"\tSoda (s)\n" <<"\tHardstuff (h)\n" <<"What's your choice: "; cin>>drink_type; } while (drink_type != 'b' && drink_type != 's' && drink_type != 'h'); if (drink_type == 's') // soda drinker - out! { cout<<"Hey, we dont soirv yours types here!"; kickedOut = true; } else // other drinkers { cout<<"Hey, c'mon in!"<<endl; do { cout<<"How much doh ya gots? "; cin>>pocket_money; } while (pocket_money < 0); if ((pocket_money < BEER_PRICE && drink_type == 'b') || (drink_type == 'h' && pocket_money < HARD_LIQUOR_PRICE)) { cout<<"You aint got enough to buy nuttin'!"; kickedOut = true; } else { if(drink_type == 'b') // beer drinker num_drinks_can_buy = static_cast<short>(pocket_money / BEER_PRICE); else // hard drinker num_drinks_can_buy = static_cast<short>(pocket_money / HARD_LIQUOR_PRICE); do { cout<<"Soo, how many drinks you gonna buy? "; cin>>num_drinks; } while (num_drinks < 0); if (num_drinks < num_drinks_can_buy) { cout<<"Ya cheapskate! Come back when you ain't so cheap!"; kickedOut = true; } else cout<<"Well, step up to the bar!!"<<endl; } // enough to buy at least one drink } // beer & hstuff drinkers } // close old enough } if (kickedOut) // standard shout cout<<KICKED_OUT<<endl; } do { cout<<"\nIs der anudder customuh out der?(y/n) "; cin>>another_customer; } while (another_customer != 'n' && another_customer != 'y'); } while (another_customer == 'y'); cout<<"\n\nMachine shutting down......."<<endl; return 0; }