Solution

// File: burgers.cpp class: cs 1570

// Purpose: this file contains the main function for the program that will help

// the user name burgers.

#include <iostream>

using namespace std;

int main()

{

// Declarations

const int MAX_CODE = 999; //this is for the max input for a 3-digit

// code for a burger

const string OWNER = "Krusty"; //tag at beginning of all names

const string TAIL = "Burger"; //tag at end of all names

const string VEGETARIAN = "Vegie"; //name of vegetarien burger

const string MEATETARIAN = "Koronary";//name of heavy meat burger

const string ONE_PATTY = "Single"; //name of single patty burger

const string TWO_PATTY = "Double"; // double

const string TRIPLE_PATTY = "Triumph";// triple

const string NO_BACON = "Health-Master"; // etc

const string ONE_BACON = "Bacon";

const string TWO_BACON = "Wilbur";

const string THREE_BACON = "Klogger";

const string NO_PICKLE = "Tastless";

const string ONE_PICKLE = "Pickly";

const string TWO_PICKLE = "Garden-Fresh";

const string THREE_PICKLE = "Kermit";

const short MIN_FATTY_MEAT_PRODUCT_FOR_A_HEART_STOPPING_BURGER = 6; //quantity

//of meat on a burger to kill a person

const short MAX_NUM_PATTIES = 3;

const short MAX_NUM_BACONS = 3;

const short MAX_NUM_PICKLES = 3;

const float COST_PER_PATTY = .75; //cost per burger patty on a burger

const float COST_PER_BACON = .5; //cost per slice of bacon on a burger

const float COST_PER_PICKLE = .25; //cost per pickle slice on a burger

string burger_name; //the final burger name

string first_part, second_part, third_part; // parts of the name

short first_dig, second_dig, third_dig; //digits of user input

short code;

float cost;

bool quit = false;

bool invalid_digit = false;

cout.setf(ios::fixed);

cout.setf(ios::showpoint);

cout.precision(2);

// Greet and Read in user input

cout<<"\n\n\nGreetings, "<<OWNER<<", ... so you wanna change the menu?"<<endl

<<endl;

do

{

invalid_digit = false;

do

{

cout<<"\n\tEnter a 3-digit code: ";

cin>>code;

} while (code < 0 || code > MAX_CODE); // must be 3-digit code input

first_dig = code/100; //these 3 lines of code must

second_dig = (code/10)%10; //change if the code become

third_dig = code%10; //different number of digits

// Figuring out the acceptability of the code

if(0 == first_dig && 0 == second_dig && 0 == third_dig) //000 or 0 quits

quit = true;

else //not quitting

{

if(0 == first_dig) // no patty - error

{

cout<<"\n\tERROR: Invalid code....please try again\n"<<endl;

invalid_digit = true;

}

else if (first_dig > MAX_NUM_PATTIES || second_dig > MAX_NUM_BACONS ||

third_dig > MAX_NUM_PICKLES)

{

cout<<"\tERROR: code exceeds max number of ingredients in some way..."

" try again"<<endl;

invalid_digit = true;

}

/* SPECIAL BURGERS */

else if (third_dig >= (first_dig + second_dig))

burger_name = VEGETARIAN;

else if (MIN_FATTY_MEAT_PRODUCT_FOR_A_HEART_STOPPING_BURGER == first_dig

+ second_dig && (0== third_dig || 1== third_dig))

burger_name = MEATETARIAN;

/* OTHER (STANDARD) CASES */

else

{

/* figuring first part of the burger name */

if (1 == first_dig)

first_part = ONE_PATTY;

else if (2 == first_dig)

first_part = TWO_PATTY;

else if (3 == first_dig)

first_part = TRIPLE_PATTY;

/* figuring second part of name */

if (0 == second_dig)

second_part = NO_BACON;

else if(1 == second_dig)

second_part = ONE_BACON;

else if (2 == second_dig)

second_part = TWO_BACON;

else if (3 == second_dig)

second_part = THREE_BACON;

/* figuring third part of name */

if (0 == third_dig)

third_part = NO_PICKLE;

else if (1 == third_dig)

third_part = ONE_PICKLE;

else if (2 == third_dig)

third_part = TWO_PICKLE;

else if (3 == third_dig)

third_part = THREE_PICKLE;

/* put parts together */

burger_name = first_part + " " + second_part + " " + third_part;

}

}

if (!invalid_digit)

{ /* build the burger name */

burger_name = OWNER + " " + burger_name + " " + TAIL; // standard output

cout<<"\nThe name of the burger is ..... "<<burger_name<<endl;

cost = first_dig * COST_PER_PATTY + second_dig * COST_PER_BACON +

third_dig * COST_PER_PICKLE;

cout<<"\tand the cost will be ..... $"<<cost<<endl<<endl;

}

} while (!quit);

cout<<"\n\nSee ya later, "<<OWNER<<endl<<endl;

return 0;

}