Solution

// Programmer: Clayton Price date: 2/17/13

// File: donut_tops.cpp class: cs 53

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

// the user (Marge) figure what kind of doughnut to make for Homer.

#include <iostream>

using namespace std;

int main()

{

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

// constants

const string BASE1 = "Wiggum doughnut";

const string BASE2 = "Krusty doughnut";

const short BASE1_BONUS = 2; //extra TOP4 bonus

const float BASE1_PTS = 10;

const float BASE2_PTS = 10;

const string TOP1 = "stips of bacon";

const string TOP2 = "pat of butter";

const string TOP3 = "ounces of Velveeta";

const string TOP4 = "chicken skins";

const string TOP5 = "dollup of grease-cream";

const string CONSOLATION = "beer";

const short TOP5_LEVEL = 2;

const float TOP1_PTS = 5;

const float TOP2_PTS = 3;

const float TOP3_PTS = 6;

const float TOP4_PTS = 50;

const float TOP5_PTS = 13;

const float CONSOLATION_PTS = 4;

const string USER = "Marge";

const short MAX_TOPPINGS = 3;

const short MIN_THUMPS = 0;

const short MIN_DOHS = 1;

const short NUM_OF_STEPS = 10;

// input variables

short num_thumps = 0;

short num_dohs = 0;

short num_steps = 0;

short num_clothing = 0;

// calculating variables

short top1_count = 0;

short top2_count = 0;

short top3_count = 0;

short num_tops = 0;

short score = 0;

short tumbled_steps = 0;

string base; //not a musical instrument - base for

// the doughnut or CONSOLUTION

string top1,top2,top3; //need more if max num toppings increases

/* --------------------- WELCOMES AND USER INPUT ----------------- */

cout << "\n\n\nWelcome "<<USER<<" to the doughnut computer..."<<endl<<endl;

cout << "Please enter the following information:"<<endl;

cout << "\tThe number of thumps Homer makes: ";

cin >> num_thumps;

if (num_thumps < MIN_THUMPS)

base = CONSOLATION;

else

{

cout << "\tThe number of times Homer says \"Doh!\": ";

cin >> num_dohs;

if (num_dohs < MIN_DOHS)

base = CONSOLATION;

else

{

cout << "\tThe number of steps before falling: ";

cin >> num_steps;

if (num_steps < 0 || num_steps > NUM_OF_STEPS)

base = CONSOLATION;

else

{

tumbled_steps = NUM_OF_STEPS - num_steps;

cout << "\tThe number of items of clothing missing: ";

cin >> num_clothing;

if (num_clothing < 0)

base = CONSOLATION;

}

}

}

/* ----------------------- COMPUTING OUTPUT ----------------- */

if (base != CONSOLATION) // REASONABLE INPUTS

{

//figure base

if (num_thumps%2==0) //even thumps - condition 1

{

base = BASE2;

top1 = TOP1;

top1_count = num_dohs;

score+=(BASE2_PTS + top1_count*TOP1_PTS);

}

else

{

base = BASE1;

top1 = TOP2;

top1_count = num_dohs;

score+=(BASE1_PTS + top1_count*TOP2_PTS);

}

num_tops = 1; //first topping added

top2 = TOP3;

num_tops = 2; //second topping added

top2_count = num_dohs + tumbled_steps;

score+=(top2_count*TOP3_PTS);

if (num_clothing%3 == 0)

{

top3 = TOP4; //third topping added

top3_count =1;

num_tops = 3;

score+=(top3_count*TOP4_PTS);

}

if (num_clothing == 0 && base == BASE1 && num_tops <= MAX_TOPPINGS)

{

top3_count+=BASE1_BONUS;

score+=(BASE1_BONUS*TOP4_PTS);

}

if (num_clothing > TOP5_LEVEL && num_tops < MAX_TOPPINGS)

{

top3 = TOP5;

top3_count = 1;

score+=(top3_count*TOP5_PTS);

}

}

else

score = CONSOLATION_PTS;

/* -------------------------OUTPUT------------------------ */

cout<<USER<<", you will give Homer a "<<base;

if (base != CONSOLATION)

{

cout<<" with the following on it:"<<endl<<endl;

switch (num_tops) //very clever output mechanism!

{

case 3:

cout<<"\t"<<top3_count<<" "<<top3<<endl;

case 2:

cout<<"\t"<<top2_count<<" "<<top2<<endl;

case 1:

cout<<"\t"<<top1_count<<" "<<top1<<endl;

}

}

cout<<endl<<USER<<", the cost to Homer will be "<<score<<"!!"<<endl<<endl;

cout<<"\n\nThat's all for now. Exiting.............."<<endl<<endl;

return 0;

}