SlideShare a Scribd company logo
1 of 20
Download to read offline
Can someone run this and take a screen shot of it and post it, it is not working on my mac. thank
you guys!!
include
#include
#include //to maintain the input for soda
#include
using namespace std;
//structure containing the soda information: drink name, price, and quantity
struct sodaData
{
string sodaName;
double sodaPrice;
int sodaQuant;
};
//time to make the array for the structure
const int SIZE = 5;
//array - had to make this global to make the program do what i intended
sodaData sodaMachine[SIZE] = { //preloading the array of structures
{ "COLA", .75, 20 }, //sub 0
{ "ROOT BEER", .75, 20 }, //sub 1
{ "LEMON-LIME", .75, 20 }, //sub 2
{ "GRAPE SODA", .80, 0 }, //sub 3 - this is set to 0 for ease of testing purposes
{ "CREAM SODA", .80, 20 }, //sub 4
}; //end the array of structures
//prototypes to handle the sodas individually. a switch will be used
//to determin which will be used
void sodaCola(double &);
void sodaRootBeer(double &);
void sodaLemon(double &);
void sodaGrape(double &);
void sodaCream(double &);
void getSoda(int &); //this is just to get user input
int main()
{
//variables to accept user input
int userSoda;
double earnedIncome = 0; //this is to hold the total earned by the machine
char again; //to redo the whole thing
int counter = 0; //added this here so it can be used outside of the for loop
cout << "Welcome to the Drink Machine Simulator. ";
cout << " ";
cout << "To begin, we will accept the soda that you wish the purchase. ";
cout << " ";
do
{
//call the input module, sending the user input for soda
cout << setprecision(2) << showpoint;
cout << setw(12) << "Drink Name" << setw(20) << "Cost in cents"
<< setw(20) << "Number in Machine ";
cout << "---------------------------------------------------------- ";
//loop to process the menu
for (counter = 0; counter < 5; counter++)
{
//display all of the array contents one-by-one
cout << counter+1 << ". " << setw(12) << sodaMachine[counter].sodaName
<< setw(18) << sodaMachine[counter].sodaPrice << setw(18) <<
sodaMachine[counter].sodaQuant
<< " ";
}
//display the quit option
cout << counter+1 << ". Quit ";
//proceed to accept input
getSoda(userSoda);
//now that the referenced variable is a number, this switch will
//take the user to the appropriate soda function
switch (userSoda)
{
case 1:
//it would be a good idea to test to see if there's any in the machine?
if (sodaMachine[0].sodaQuant > 0)
sodaCola(earnedIncome);
else
cout << "This beverage appears to be sold out. ";
break;
case 2:
if (sodaMachine[1].sodaQuant > 0)
sodaCola(earnedIncome);
else
cout << "This beverage appears to be sold out. ";
break;
case 3:
if (sodaMachine[2].sodaQuant > 0)
sodaLemon(earnedIncome);
else
cout << "This beverage appears to be sold out. ";
break;
case 4:
if (sodaMachine[3].sodaQuant > 0)
sodaGrape(earnedIncome);
else
cout << "This beverage appears to be sold out. ";
break;
case 5:
if (sodaMachine[4].sodaQuant > 0)
sodaCream(earnedIncome);
else
cout << "This beverage appears to be sold out. ";
break;
case 6:
break;
};
cout << " Would you like to purchase another soda? ";
cout << "Please enter Y to purchase another beverage. ";
cin >> again;
} while (toupper(again) == 'Y');
cout << setprecision(3) << showpoint;
cout << " ";
cout << "We kept a tally of how much money the machine earned ";
cout << "as you ran your simulation. ";
cout << "The total comes out to: $" << earnedIncome << ". ";
//this is how i end all my programs. i love the extra line and the pause
cout << " ";
system("pause");
return 0;
}
/* function getSoda
function will accept the int choice soda as a reference to send it back
to drive the menu.
*see note at beginning
*/
void getSoda(int & soda)
{
//create variable for the switch
bool drinkTrue;
cout << "Please input the soda to be purchased. ";
cout << "Please use the number of the soda. ";
cin >> soda;
//time to test for the pretest loop
switch (soda)
{
case 1:
drinkTrue = true;
break;
case 2:
drinkTrue = true;
break;
case 3:
drinkTrue = true;
break;
case 4:
drinkTrue = true;
break;
case 5:
drinkTrue = true;
break;
case 6:
drinkTrue = true;
break;
default:
drinkTrue = false;
};
while (drinkTrue !=true)
{
//if any of the above were incorrect, it would go into here
cout << "Looks like you keyed in the wrong thing. Try again. ";
cout << "Less fail this time, eh? ";
cout << "Please input the soda to be purchased. ";
cout << "Please use the number of the soda. ";
cin >> soda;
switch (soda)
{
case 1:
drinkTrue = true;
break;
case 2:
drinkTrue = true;
break;
case 3:
drinkTrue = true;
break;
case 4:
drinkTrue = true;
break;
case 5:
drinkTrue = true;
break;
case 6:
drinkTrue = true;
break;
default:
drinkTrue = false;
};
//test the new input
}
}
/* function sodaCola
accepts the sodaData structure array to do the math with and change the
quantity of drinks in the machine and the income to set the earned income.
will return the array structure at cola sub which is 0.
*/
void sodaCola(double & income)
{
//at this point we have to declare a variable to accept the amount
//of money being spent on the soda
double userMoney;
cout << " ";
cout << "You have selected Cola to purchase. ";
cout << "Please enter in the amount of money you wish to ";
cout << "spend on this purchse. ";
cout << "Amounts between 0 and $1.00 only are accepted. ";
cin >> userMoney;
//validation for if the amount entered is negative or greater than $1.00
while (userMoney < 0 || userMoney > 1.0)
{
cout << " ";
cout << "Looks like you didn't do what I asked. ";
cout << "Please try again, only this time, only something between ";
cout << "0 and $1.00. ";
cin >> userMoney;
}
//not asked for, but it would be hard to sell a soda if there
//wasn't enough money for it.
while (userMoney < sodaMachine[0].sodaPrice)
{
cout << " ";
cout << "Not enough money ";
cout << "Please try again, only this time, only something between ";
cout << "0 and $1.00. ";
cin >> userMoney;
}
//now that the money has been verified, time to do a math
sodaMachine[0].sodaQuant--;
income += sodaMachine[0].sodaPrice;
cout << "Given that you supplied more than the cost of the drink, ";
cout << "$" << userMoney - sodaMachine[0].sodaPrice << " will be returned to you. ";
}
/* function sodaRootBeer
accepts the sodaData structure array to do the math with and change the
quantity of drinks in the machine and the income to set the earned income.
will return the array structure at root beer sub which is 1.
*/
void sodaRootBeer(double & income)
{
//at this point we have to declare a variable to accept the amount
//of money being spent on the soda
double userMoney;
cout << " ";
cout << "You have selected Root Beer to purchase. ";
cout << "Please enter in the amount of money you wish to ";
cout << "spend on this purchse. ";
cout << "Amounts between 0 and $1.00 only are accepted. ";
cin >> userMoney;
//validation for if the amount entered is negative or greater than $1.00
while (userMoney < 0 || userMoney > 1.0)
{
cout << " ";
cout << "Looks like you didn't do what I asked. ";
cout << "Please try again, only this time, only something between ";
cout << "0 and $1.00. ";
cin >> userMoney;
}
//not asked for, but it would be hard to sell a soda if there
//wasn't enough money for it.
while (userMoney < sodaMachine[1].sodaPrice)
{
cout << " ";
cout << "Not enough money ";
cout << "Please try again, only this time, only something between ";
cout << "0 and $1.00. ";
cin >> userMoney;
}
//now that the money has been verified, time to do a math
sodaMachine[1].sodaQuant--;
income += sodaMachine[1].sodaPrice;
cout << "Given that you supplied more than the cost of the drink, ";
cout << "$" << userMoney - sodaMachine[1].sodaPrice << " will be returned to you. ";
}
/* function sodaLemon
accepts the sodaData structure array to do the math with and change the
quantity of drinks in the machine and the income to set the earned income.
will return the array structure at lemon-lime sub which is 2.
*/
void sodaLemon(double & income)
{
//at this point we have to declare a variable to accept the amount
//of money being spent on the soda
double userMoney;
cout << " ";
cout << "You have selected Lemon-Lime to purchase. ";
cout << "Please enter in the amount of money you wish to ";
cout << "spend on this purchse. ";
cout << "Amounts between 0 and $1.00 only are accepted. ";
cin >> userMoney;
//validation for if the amount entered is negative or greater than $1.00
while (userMoney < 0 || userMoney > 1.0)
{
cout << " ";
cout << "Looks like you didn't do what I asked. ";
cout << "Please try again, only this time, only something between ";
cout << "0 and $1.00. ";
cin >> userMoney;
}
//not asked for, but it would be hard to sell a soda if there
//wasn't enough money for it.
while (userMoney < sodaMachine[2].sodaPrice)
{
cout << " ";
cout << "Not enough money ";
cout << "Please try again, only this time, only something between ";
cout << "0 and $1.00. ";
cin >> userMoney;
}
//now that the money has been verified, time to do a math
sodaMachine[2].sodaQuant--;
income += sodaMachine[2].sodaPrice;
cout << "Given that you supplied more than the cost of the drink, ";
cout << "$" << userMoney - sodaMachine[2].sodaPrice << " will be returned to you. ";
}
/* function sodaGrape
accepts the sodaData structure array to do the math with and change the
quantity of drinks in the machine and the income to set the earned income.
will return the array structure at grape soda sub which is 3.
*/
void sodaGrape(double & income)
{
//at this point we have to declare a variable to accept the amount
//of money being spent on the soda
double userMoney;
cout << " ";
cout << "You have selected Grape Soda to purchase. ";
cout << "Please enter in the amount of money you wish to ";
cout << "spend on this purchse. ";
cout << "Amounts between 0 and $1.00 only are accepted. ";
cin >> userMoney;
//validation for if the amount entered is negative or greater than $1.00
while (userMoney < 0 || userMoney > 1.0)
{
cout << " ";
cout << "Looks like you didn't do what I asked. ";
cout << "Please try again, only this time, only something between ";
cout << "0 and $1.00. ";
cin >> userMoney;
}
//not asked for, but it would be hard to sell a soda if there
//wasn't enough money for it.
while (userMoney < sodaMachine[3].sodaPrice)
{
cout << " ";
cout << "Not enough money ";
cout << "Please try again, only this time, only something between ";
cout << "0 and $1.00. ";
cin >> userMoney;
}
//now that the money has been verified, time to do a math
sodaMachine[3].sodaQuant--;
income += sodaMachine[3].sodaPrice;
cout << "Given that you supplied more than the cost of the drink, ";
cout << "$" << userMoney - sodaMachine[3].sodaPrice << " will be returned to you. ";
}
/* function sodaCream
accepts the sodaData structure array to do the math with and change the
quantity of drinks in the machine and the income to set the earned income.
will return the array structure at cream soda sub which is 4.
*/
void sodaCream(double & income)
{
//at this point we have to declare a variable to accept the amount
//of money being spent on the soda
double userMoney;
cout << " ";
cout << "You have selected Cream Soda to purchase. ";
cout << "Please enter in the amount of money you wish to ";
cout << "spend on this purchse. ";
cout << "Amounts between 0 and $1.00 only are accepted. ";
cin >> userMoney;
//validation for if the amount entered is negative or greater than $1.00
while (userMoney < 0 || userMoney > 1.0)
{
cout << " ";
cout << "Looks like you didn't do what I asked. ";
cout << "Please try again, only this time, only something between ";
cout << "0 and $1.00. ";
cin >> userMoney;
}
//not asked for, but it would be hard to sell a soda if there
//wasn't enough money for it.
while (userMoney < sodaMachine[4].sodaPrice)
{
cout << " ";
cout << "Not enough money ";
cout << "Please try again, only this time, only something between ";
cout << "0 and $1.00. ";
cin >> userMoney;
}
//now that the money has been verified, time to do a math
sodaMachine[4].sodaQuant--;
income += sodaMachine[4].sodaPrice;
cout << "Given that you supplied more than the cost of the drink, ";
cout << "$" << userMoney - sodaMachine[4].sodaPrice << " will be returned to you. ";
}
Solution
#include
#include
#include //to maintain the input for soda
#include
using namespace std;
struct sodaData
{
string sodaName;
double sodaPrice;
int sodaQuant;
};
const int SIZE = 5;
sodaData sodaMachine[SIZE] = { //preloading the array of structures
{ "COLA", .75, 20 }, //sub 0
{ "ROOT BEER", .75, 20 }, //sub 1
{ "LEMON-LIME", .75, 20 }, //sub 2
{ "GRAPE SODA", .80, 0 }, //sub 3 - this is set to 0 for ease of testing purposes
{ "CREAM SODA", .80, 20 }, //sub 4
}; //end the array of structures
void sodaCola(double &);
void sodaRootBeer(double &);
void sodaLemon(double &);
void sodaGrape(double &);
void sodaCream(double &);
void getSoda(int &); //this is just to get user input
int main()
{
int userSoda;
double earnedIncome = 0; //this is to hold the total earned by the machine
char again; //to redo the whole thing
int counter = 0; //added this here so it can be used outside of the for loop
cout << "Welcome to the Drink Machine Simulator. ";
cout << " ";
cout << "To begin, we will accept the soda that you wish the purchase. ";
cout << " ";
do
{
cout << setprecision(2) << showpoint;
cout << setw(12) << "Drink Name" << setw(20) << "Cost in cents"
<< setw(20) << "Number in Machine ";
cout << "---------------------------------------------------------- ";
for (counter = 0; counter < 5; counter++)
{
cout << counter+1 << ". " << setw(12) << sodaMachine[counter].sodaName
<< setw(18) << sodaMachine[counter].sodaPrice << setw(18) <<
sodaMachine[counter].sodaQuant
<< " ";
}
cout << counter+1 << ". Quit ";
getSoda(userSoda);
switch (userSoda)
{
case 1:
if (sodaMachine[0].sodaQuant > 0)
sodaCola(earnedIncome);
else
cout << "This beverage appears to be sold out. ";
break;
case 2:
if (sodaMachine[1].sodaQuant > 0)
sodaCola(earnedIncome);
else
cout << "This beverage appears to be sold out. ";
break;
case 3:
if (sodaMachine[2].sodaQuant > 0)
sodaLemon(earnedIncome);
else
cout << "This beverage appears to be sold out. ";
break;
case 4:
if (sodaMachine[3].sodaQuant > 0)
sodaGrape(earnedIncome);
else
cout << "This beverage appears to be sold out. ";
break;
case 5:
if (sodaMachine[4].sodaQuant > 0)
sodaCream(earnedIncome);
else
cout << "This beverage appears to be sold out. ";
break;
case 6:
break;
};
cout << " Would you like to purchase another soda? ";
cout << "Please enter Y to purchase another beverage. ";
cin >> again;
} while (toupper(again) == 'Y');
cout << setprecision(3) << showpoint;
cout << " ";
cout << "We kept a tally of how much money the machine earned ";
cout << "as you ran your simulation. ";
cout << "The total comes out to: $" << earnedIncome << ". ";
cout << " ";
system("pause");
return 0;
}
void getSoda(int & soda)
{
bool drinkTrue;
cout << "Please input the soda to be purchased. ";
cout << "Please use the number of the soda. ";
cin >> soda;
switch (soda)
{
case 1:
drinkTrue = true;
break;
case 2:
drinkTrue = true;
break;
case 3:
drinkTrue = true;
break;
case 4:
drinkTrue = true;
break;
case 5:
drinkTrue = true;
break;
case 6:
drinkTrue = true;
break;
default:
drinkTrue = false;
};
while (drinkTrue !=true)
{
cout << "Looks like you keyed in the wrong thing. Try again. ";
cout << "Less fail this time, eh? ";
cout << "Please input the soda to be purchased. ";
cout << "Please use the number of the soda. ";
cin >> soda;
switch (soda)
{
case 1:
drinkTrue = true;
break;
case 2:
drinkTrue = true;
break;
case 3:
drinkTrue = true;
break;
case 4:
drinkTrue = true;
break;
case 5:
drinkTrue = true;
break;
case 6:
drinkTrue = true;
break;
default:
drinkTrue = false;
};
//test the new input
}
}
void sodaCola(double & income)
{
double userMoney;
cout << " ";
cout << "You have selected Cola to purchase. ";
cout << "Please enter in the amount of money you wish to ";
cout << "spend on this purchse. ";
cout << "Amounts between 0 and $1.00 only are accepted. ";
cin >> userMoney;
while (userMoney < 0 || userMoney > 1.0)
{
cout << " ";
cout << "Looks like you didn't do what I asked. ";
cout << "Please try again, only this time, only something between ";
cout << "0 and $1.00. ";
cin >> userMoney;
}
while (userMoney < sodaMachine[0].sodaPrice)
{
cout << " ";
cout << "Not enough money ";
cout << "Please try again, only this time, only something between ";
cout << "0 and $1.00. ";
cin >> userMoney;
}
sodaMachine[0].sodaQuant--;
income += sodaMachine[0].sodaPrice;
cout << "Given that you supplied more than the cost of the drink, ";
cout << "$" << userMoney - sodaMachine[0].sodaPrice << " will be returned to you. ";
}
void sodaRootBeer(double & income)
{
double userMoney;
cout << " ";
cout << "You have selected Root Beer to purchase. ";
cout << "Please enter in the amount of money you wish to ";
cout << "spend on this purchse. ";
cout << "Amounts between 0 and $1.00 only are accepted. ";
cin >> userMoney;
while (userMoney < 0 || userMoney > 1.0)
{
cout << " ";
cout << "Looks like you didn't do what I asked. ";
cout << "Please try again, only this time, only something between ";
cout << "0 and $1.00. ";
cin >> userMoney;
}
while (userMoney < sodaMachine[1].sodaPrice)
{
cout << " ";
cout << "Not enough money ";
cout << "Please try again, only this time, only something between ";
cout << "0 and $1.00. ";
cin >> userMoney;
}
sodaMachine[1].sodaQuant--;
income += sodaMachine[1].sodaPrice;
cout << "Given that you supplied more than the cost of the drink, ";
cout << "$" << userMoney - sodaMachine[1].sodaPrice << " will be returned to you. ";
}
void sodaLemon(double & income)
{
double userMoney;
cout << " ";
cout << "You have selected Lemon-Lime to purchase. ";
cout << "Please enter in the amount of money you wish to ";
cout << "spend on this purchse. ";
cout << "Amounts between 0 and $1.00 only are accepted. ";
cin >> userMoney;
while (userMoney < 0 || userMoney > 1.0)
{
cout << " ";
cout << "Looks like you didn't do what I asked. ";
cout << "Please try again, only this time, only something between ";
cout << "0 and $1.00. ";
cin >> userMoney;
}
while (userMoney < sodaMachine[2].sodaPrice)
{
cout << " ";
cout << "Not enough money ";
cout << "Please try again, only this time, only something between ";
cout << "0 and $1.00. ";
cin >> userMoney;
}
sodaMachine[2].sodaQuant--;
income += sodaMachine[2].sodaPrice;
cout << "Given that you supplied more than the cost of the drink, ";
cout << "$" << userMoney - sodaMachine[2].sodaPrice << " will be returned to you. ";
}
void sodaGrape(double & income)
{
double userMoney;
cout << " ";
cout << "You have selected Grape Soda to purchase. ";
cout << "Please enter in the amount of money you wish to ";
cout << "spend on this purchse. ";
cout << "Amounts between 0 and $1.00 only are accepted. ";
cin >> userMoney;
//validation for if the amount entered is negative or greater than $1.00
while (userMoney < 0 || userMoney > 1.0)
{
cout << " ";
cout << "Looks like you didn't do what I asked. ";
cout << "Please try again, only this time, only something between ";
cout << "0 and $1.00. ";
cin >> userMoney;
}
while (userMoney < sodaMachine[3].sodaPrice)
{
cout << " ";
cout << "Not enough money ";
cout << "Please try again, only this time, only something between ";
cout << "0 and $1.00. ";
cin >> userMoney;
}
sodaMachine[3].sodaQuant--;
income += sodaMachine[3].sodaPrice;
cout << "Given that you supplied more than the cost of the drink, ";
cout << "$" << userMoney - sodaMachine[3].sodaPrice << " will be returned to you. ";
}
void sodaCream(double & income)
{
double userMoney;
cout << " ";
cout << "You have selected Cream Soda to purchase. ";
cout << "Please enter in the amount of money you wish to ";
cout << "spend on this purchse. ";
cout << "Amounts between 0 and $1.00 only are accepted. ";
cin >> userMoney;
while (userMoney < 0 || userMoney > 1.0)
{
cout << " ";
cout << "Looks like you didn't do what I asked. ";
cout << "Please try again, only this time, only something between ";
cout << "0 and $1.00. ";
cin >> userMoney;
}
while (userMoney < sodaMachine[4].sodaPrice)
{
cout << " ";
cout << "Not enough money ";
cout << "Please try again, only this time, only something between ";
cout << "0 and $1.00. ";
cin >> userMoney;
}
sodaMachine[4].sodaQuant--;
income += sodaMachine[4].sodaPrice;
cout << "Given that you supplied more than the cost of the drink, ";
cout << "$" << userMoney - sodaMachine[4].sodaPrice << " will be returned to you. ";
}

More Related Content

More from amitbagga0808

Anatomy can be studied in many ways. Regional anatomy is the study of.pdf
Anatomy can be studied in many ways. Regional anatomy is the study of.pdfAnatomy can be studied in many ways. Regional anatomy is the study of.pdf
Anatomy can be studied in many ways. Regional anatomy is the study of.pdfamitbagga0808
 
A red blood cell enters the right atrium from the superior vena cava..pdf
A red blood cell enters the right atrium from the superior vena cava..pdfA red blood cell enters the right atrium from the superior vena cava..pdf
A red blood cell enters the right atrium from the superior vena cava..pdfamitbagga0808
 
You have been hired by Planet Poachers to write a Java console appli.pdf
You have been hired by Planet Poachers to write a Java console appli.pdfYou have been hired by Planet Poachers to write a Java console appli.pdf
You have been hired by Planet Poachers to write a Java console appli.pdfamitbagga0808
 
An organism that has a normal diploid autosome set with an XXY sex c.pdf
An organism that has a normal diploid autosome set with an XXY sex c.pdfAn organism that has a normal diploid autosome set with an XXY sex c.pdf
An organism that has a normal diploid autosome set with an XXY sex c.pdfamitbagga0808
 
Which level of Orange Book protection is considered mandatory protec.pdf
Which level of Orange Book protection is considered mandatory protec.pdfWhich level of Orange Book protection is considered mandatory protec.pdf
Which level of Orange Book protection is considered mandatory protec.pdfamitbagga0808
 
Why is it an advantage for the epiglottis to fit over the trachea.pdf
Why is it an advantage for the epiglottis to fit over the trachea.pdfWhy is it an advantage for the epiglottis to fit over the trachea.pdf
Why is it an advantage for the epiglottis to fit over the trachea.pdfamitbagga0808
 
This is Function Class public abstract class Function {    .pdf
This is Function Class public abstract class Function {    .pdfThis is Function Class public abstract class Function {    .pdf
This is Function Class public abstract class Function {    .pdfamitbagga0808
 
What factors are likely to be involved in setting the limit to how lo.pdf
What factors are likely to be involved in setting the limit to how lo.pdfWhat factors are likely to be involved in setting the limit to how lo.pdf
What factors are likely to be involved in setting the limit to how lo.pdfamitbagga0808
 
What is alternative splicing What is the difference between mRNA sp.pdf
What is alternative splicing What is the difference between mRNA sp.pdfWhat is alternative splicing What is the difference between mRNA sp.pdf
What is alternative splicing What is the difference between mRNA sp.pdfamitbagga0808
 
What are histones and their role in regulating transcription. .pdf
What are histones and their role in regulating transcription. .pdfWhat are histones and their role in regulating transcription. .pdf
What are histones and their role in regulating transcription. .pdfamitbagga0808
 
What are the cellular differences between fungi and protistsSol.pdf
What are the cellular differences between fungi and protistsSol.pdfWhat are the cellular differences between fungi and protistsSol.pdf
What are the cellular differences between fungi and protistsSol.pdfamitbagga0808
 
on the basis of the above data, list the media in order according to.pdf
on the basis of the above data, list the media in order according to.pdfon the basis of the above data, list the media in order according to.pdf
on the basis of the above data, list the media in order according to.pdfamitbagga0808
 
Program In C You are required to write an interactive C program that.pdf
Program In C You are required to write an interactive C program that.pdfProgram In C You are required to write an interactive C program that.pdf
Program In C You are required to write an interactive C program that.pdfamitbagga0808
 
Prove that is L is regular and h is a homomorphism, then h(L) is.pdf
Prove that is L is regular and h is a homomorphism, then h(L) is.pdfProve that is L is regular and h is a homomorphism, then h(L) is.pdf
Prove that is L is regular and h is a homomorphism, then h(L) is.pdfamitbagga0808
 
Not sure how to do this case analysis please help me do it!1.Are t.pdf
Not sure how to do this case analysis please help me do it!1.Are t.pdfNot sure how to do this case analysis please help me do it!1.Are t.pdf
Not sure how to do this case analysis please help me do it!1.Are t.pdfamitbagga0808
 
In each of the following situations, data are obtained by conducting .pdf
In each of the following situations, data are obtained by conducting .pdfIn each of the following situations, data are obtained by conducting .pdf
In each of the following situations, data are obtained by conducting .pdfamitbagga0808
 
i need a summary book report on thw Iwoby richard wheelerSolut.pdf
i need a summary book report on thw Iwoby richard wheelerSolut.pdfi need a summary book report on thw Iwoby richard wheelerSolut.pdf
i need a summary book report on thw Iwoby richard wheelerSolut.pdfamitbagga0808
 
18 Alicia climbs into the passenger side of her boyfriend Bos car. .pdf
18 Alicia climbs into the passenger side of her boyfriend Bos car. .pdf18 Alicia climbs into the passenger side of her boyfriend Bos car. .pdf
18 Alicia climbs into the passenger side of her boyfriend Bos car. .pdfamitbagga0808
 
Imagine a scientist finds the fossils of an extinct Ichthyosaur and .pdf
Imagine a scientist finds the fossils of an extinct Ichthyosaur and .pdfImagine a scientist finds the fossils of an extinct Ichthyosaur and .pdf
Imagine a scientist finds the fossils of an extinct Ichthyosaur and .pdfamitbagga0808
 
How have your genes and enviornment interacted to produce the temper.pdf
How have your genes and enviornment interacted to produce the temper.pdfHow have your genes and enviornment interacted to produce the temper.pdf
How have your genes and enviornment interacted to produce the temper.pdfamitbagga0808
 

More from amitbagga0808 (20)

Anatomy can be studied in many ways. Regional anatomy is the study of.pdf
Anatomy can be studied in many ways. Regional anatomy is the study of.pdfAnatomy can be studied in many ways. Regional anatomy is the study of.pdf
Anatomy can be studied in many ways. Regional anatomy is the study of.pdf
 
A red blood cell enters the right atrium from the superior vena cava..pdf
A red blood cell enters the right atrium from the superior vena cava..pdfA red blood cell enters the right atrium from the superior vena cava..pdf
A red blood cell enters the right atrium from the superior vena cava..pdf
 
You have been hired by Planet Poachers to write a Java console appli.pdf
You have been hired by Planet Poachers to write a Java console appli.pdfYou have been hired by Planet Poachers to write a Java console appli.pdf
You have been hired by Planet Poachers to write a Java console appli.pdf
 
An organism that has a normal diploid autosome set with an XXY sex c.pdf
An organism that has a normal diploid autosome set with an XXY sex c.pdfAn organism that has a normal diploid autosome set with an XXY sex c.pdf
An organism that has a normal diploid autosome set with an XXY sex c.pdf
 
Which level of Orange Book protection is considered mandatory protec.pdf
Which level of Orange Book protection is considered mandatory protec.pdfWhich level of Orange Book protection is considered mandatory protec.pdf
Which level of Orange Book protection is considered mandatory protec.pdf
 
Why is it an advantage for the epiglottis to fit over the trachea.pdf
Why is it an advantage for the epiglottis to fit over the trachea.pdfWhy is it an advantage for the epiglottis to fit over the trachea.pdf
Why is it an advantage for the epiglottis to fit over the trachea.pdf
 
This is Function Class public abstract class Function {    .pdf
This is Function Class public abstract class Function {    .pdfThis is Function Class public abstract class Function {    .pdf
This is Function Class public abstract class Function {    .pdf
 
What factors are likely to be involved in setting the limit to how lo.pdf
What factors are likely to be involved in setting the limit to how lo.pdfWhat factors are likely to be involved in setting the limit to how lo.pdf
What factors are likely to be involved in setting the limit to how lo.pdf
 
What is alternative splicing What is the difference between mRNA sp.pdf
What is alternative splicing What is the difference between mRNA sp.pdfWhat is alternative splicing What is the difference between mRNA sp.pdf
What is alternative splicing What is the difference between mRNA sp.pdf
 
What are histones and their role in regulating transcription. .pdf
What are histones and their role in regulating transcription. .pdfWhat are histones and their role in regulating transcription. .pdf
What are histones and their role in regulating transcription. .pdf
 
What are the cellular differences between fungi and protistsSol.pdf
What are the cellular differences between fungi and protistsSol.pdfWhat are the cellular differences between fungi and protistsSol.pdf
What are the cellular differences between fungi and protistsSol.pdf
 
on the basis of the above data, list the media in order according to.pdf
on the basis of the above data, list the media in order according to.pdfon the basis of the above data, list the media in order according to.pdf
on the basis of the above data, list the media in order according to.pdf
 
Program In C You are required to write an interactive C program that.pdf
Program In C You are required to write an interactive C program that.pdfProgram In C You are required to write an interactive C program that.pdf
Program In C You are required to write an interactive C program that.pdf
 
Prove that is L is regular and h is a homomorphism, then h(L) is.pdf
Prove that is L is regular and h is a homomorphism, then h(L) is.pdfProve that is L is regular and h is a homomorphism, then h(L) is.pdf
Prove that is L is regular and h is a homomorphism, then h(L) is.pdf
 
Not sure how to do this case analysis please help me do it!1.Are t.pdf
Not sure how to do this case analysis please help me do it!1.Are t.pdfNot sure how to do this case analysis please help me do it!1.Are t.pdf
Not sure how to do this case analysis please help me do it!1.Are t.pdf
 
In each of the following situations, data are obtained by conducting .pdf
In each of the following situations, data are obtained by conducting .pdfIn each of the following situations, data are obtained by conducting .pdf
In each of the following situations, data are obtained by conducting .pdf
 
i need a summary book report on thw Iwoby richard wheelerSolut.pdf
i need a summary book report on thw Iwoby richard wheelerSolut.pdfi need a summary book report on thw Iwoby richard wheelerSolut.pdf
i need a summary book report on thw Iwoby richard wheelerSolut.pdf
 
18 Alicia climbs into the passenger side of her boyfriend Bos car. .pdf
18 Alicia climbs into the passenger side of her boyfriend Bos car. .pdf18 Alicia climbs into the passenger side of her boyfriend Bos car. .pdf
18 Alicia climbs into the passenger side of her boyfriend Bos car. .pdf
 
Imagine a scientist finds the fossils of an extinct Ichthyosaur and .pdf
Imagine a scientist finds the fossils of an extinct Ichthyosaur and .pdfImagine a scientist finds the fossils of an extinct Ichthyosaur and .pdf
Imagine a scientist finds the fossils of an extinct Ichthyosaur and .pdf
 
How have your genes and enviornment interacted to produce the temper.pdf
How have your genes and enviornment interacted to produce the temper.pdfHow have your genes and enviornment interacted to produce the temper.pdf
How have your genes and enviornment interacted to produce the temper.pdf
 

Recently uploaded

Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...KokoStevan
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterMateoGardella
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfChris Hunter
 

Recently uploaded (20)

Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 

Can someone run this and take a screen shot of it and post it, it is.pdf

  • 1. Can someone run this and take a screen shot of it and post it, it is not working on my mac. thank you guys!! include #include #include //to maintain the input for soda #include using namespace std; //structure containing the soda information: drink name, price, and quantity struct sodaData { string sodaName; double sodaPrice; int sodaQuant; }; //time to make the array for the structure const int SIZE = 5; //array - had to make this global to make the program do what i intended sodaData sodaMachine[SIZE] = { //preloading the array of structures { "COLA", .75, 20 }, //sub 0 { "ROOT BEER", .75, 20 }, //sub 1 { "LEMON-LIME", .75, 20 }, //sub 2 { "GRAPE SODA", .80, 0 }, //sub 3 - this is set to 0 for ease of testing purposes { "CREAM SODA", .80, 20 }, //sub 4 }; //end the array of structures //prototypes to handle the sodas individually. a switch will be used //to determin which will be used void sodaCola(double &); void sodaRootBeer(double &); void sodaLemon(double &); void sodaGrape(double &); void sodaCream(double &); void getSoda(int &); //this is just to get user input int main() { //variables to accept user input
  • 2. int userSoda; double earnedIncome = 0; //this is to hold the total earned by the machine char again; //to redo the whole thing int counter = 0; //added this here so it can be used outside of the for loop cout << "Welcome to the Drink Machine Simulator. "; cout << " "; cout << "To begin, we will accept the soda that you wish the purchase. "; cout << " "; do { //call the input module, sending the user input for soda cout << setprecision(2) << showpoint; cout << setw(12) << "Drink Name" << setw(20) << "Cost in cents" << setw(20) << "Number in Machine "; cout << "---------------------------------------------------------- "; //loop to process the menu for (counter = 0; counter < 5; counter++) { //display all of the array contents one-by-one cout << counter+1 << ". " << setw(12) << sodaMachine[counter].sodaName << setw(18) << sodaMachine[counter].sodaPrice << setw(18) << sodaMachine[counter].sodaQuant << " "; } //display the quit option cout << counter+1 << ". Quit "; //proceed to accept input getSoda(userSoda); //now that the referenced variable is a number, this switch will //take the user to the appropriate soda function switch (userSoda) { case 1: //it would be a good idea to test to see if there's any in the machine? if (sodaMachine[0].sodaQuant > 0) sodaCola(earnedIncome);
  • 3. else cout << "This beverage appears to be sold out. "; break; case 2: if (sodaMachine[1].sodaQuant > 0) sodaCola(earnedIncome); else cout << "This beverage appears to be sold out. "; break; case 3: if (sodaMachine[2].sodaQuant > 0) sodaLemon(earnedIncome); else cout << "This beverage appears to be sold out. "; break; case 4: if (sodaMachine[3].sodaQuant > 0) sodaGrape(earnedIncome); else cout << "This beverage appears to be sold out. "; break; case 5: if (sodaMachine[4].sodaQuant > 0) sodaCream(earnedIncome); else cout << "This beverage appears to be sold out. "; break; case 6: break; }; cout << " Would you like to purchase another soda? "; cout << "Please enter Y to purchase another beverage. "; cin >> again; } while (toupper(again) == 'Y'); cout << setprecision(3) << showpoint;
  • 4. cout << " "; cout << "We kept a tally of how much money the machine earned "; cout << "as you ran your simulation. "; cout << "The total comes out to: $" << earnedIncome << ". "; //this is how i end all my programs. i love the extra line and the pause cout << " "; system("pause"); return 0; } /* function getSoda function will accept the int choice soda as a reference to send it back to drive the menu. *see note at beginning */ void getSoda(int & soda) { //create variable for the switch bool drinkTrue; cout << "Please input the soda to be purchased. "; cout << "Please use the number of the soda. "; cin >> soda; //time to test for the pretest loop switch (soda) { case 1: drinkTrue = true; break; case 2: drinkTrue = true; break; case 3: drinkTrue = true; break; case 4:
  • 5. drinkTrue = true; break; case 5: drinkTrue = true; break; case 6: drinkTrue = true; break; default: drinkTrue = false; }; while (drinkTrue !=true) { //if any of the above were incorrect, it would go into here cout << "Looks like you keyed in the wrong thing. Try again. "; cout << "Less fail this time, eh? "; cout << "Please input the soda to be purchased. "; cout << "Please use the number of the soda. "; cin >> soda; switch (soda) { case 1: drinkTrue = true; break; case 2: drinkTrue = true; break; case 3: drinkTrue = true; break; case 4: drinkTrue = true; break; case 5: drinkTrue = true; break;
  • 6. case 6: drinkTrue = true; break; default: drinkTrue = false; }; //test the new input } } /* function sodaCola accepts the sodaData structure array to do the math with and change the quantity of drinks in the machine and the income to set the earned income. will return the array structure at cola sub which is 0. */ void sodaCola(double & income) { //at this point we have to declare a variable to accept the amount //of money being spent on the soda double userMoney; cout << " "; cout << "You have selected Cola to purchase. "; cout << "Please enter in the amount of money you wish to "; cout << "spend on this purchse. "; cout << "Amounts between 0 and $1.00 only are accepted. "; cin >> userMoney; //validation for if the amount entered is negative or greater than $1.00 while (userMoney < 0 || userMoney > 1.0) { cout << " "; cout << "Looks like you didn't do what I asked. "; cout << "Please try again, only this time, only something between "; cout << "0 and $1.00. "; cin >> userMoney; }
  • 7. //not asked for, but it would be hard to sell a soda if there //wasn't enough money for it. while (userMoney < sodaMachine[0].sodaPrice) { cout << " "; cout << "Not enough money "; cout << "Please try again, only this time, only something between "; cout << "0 and $1.00. "; cin >> userMoney; } //now that the money has been verified, time to do a math sodaMachine[0].sodaQuant--; income += sodaMachine[0].sodaPrice; cout << "Given that you supplied more than the cost of the drink, "; cout << "$" << userMoney - sodaMachine[0].sodaPrice << " will be returned to you. "; } /* function sodaRootBeer accepts the sodaData structure array to do the math with and change the quantity of drinks in the machine and the income to set the earned income. will return the array structure at root beer sub which is 1. */ void sodaRootBeer(double & income) { //at this point we have to declare a variable to accept the amount //of money being spent on the soda double userMoney; cout << " "; cout << "You have selected Root Beer to purchase. "; cout << "Please enter in the amount of money you wish to "; cout << "spend on this purchse. "; cout << "Amounts between 0 and $1.00 only are accepted. "; cin >> userMoney; //validation for if the amount entered is negative or greater than $1.00 while (userMoney < 0 || userMoney > 1.0)
  • 8. { cout << " "; cout << "Looks like you didn't do what I asked. "; cout << "Please try again, only this time, only something between "; cout << "0 and $1.00. "; cin >> userMoney; } //not asked for, but it would be hard to sell a soda if there //wasn't enough money for it. while (userMoney < sodaMachine[1].sodaPrice) { cout << " "; cout << "Not enough money "; cout << "Please try again, only this time, only something between "; cout << "0 and $1.00. "; cin >> userMoney; } //now that the money has been verified, time to do a math sodaMachine[1].sodaQuant--; income += sodaMachine[1].sodaPrice; cout << "Given that you supplied more than the cost of the drink, "; cout << "$" << userMoney - sodaMachine[1].sodaPrice << " will be returned to you. "; } /* function sodaLemon accepts the sodaData structure array to do the math with and change the quantity of drinks in the machine and the income to set the earned income. will return the array structure at lemon-lime sub which is 2. */ void sodaLemon(double & income) { //at this point we have to declare a variable to accept the amount //of money being spent on the soda double userMoney; cout << " "; cout << "You have selected Lemon-Lime to purchase. "; cout << "Please enter in the amount of money you wish to ";
  • 9. cout << "spend on this purchse. "; cout << "Amounts between 0 and $1.00 only are accepted. "; cin >> userMoney; //validation for if the amount entered is negative or greater than $1.00 while (userMoney < 0 || userMoney > 1.0) { cout << " "; cout << "Looks like you didn't do what I asked. "; cout << "Please try again, only this time, only something between "; cout << "0 and $1.00. "; cin >> userMoney; } //not asked for, but it would be hard to sell a soda if there //wasn't enough money for it. while (userMoney < sodaMachine[2].sodaPrice) { cout << " "; cout << "Not enough money "; cout << "Please try again, only this time, only something between "; cout << "0 and $1.00. "; cin >> userMoney; } //now that the money has been verified, time to do a math sodaMachine[2].sodaQuant--; income += sodaMachine[2].sodaPrice; cout << "Given that you supplied more than the cost of the drink, "; cout << "$" << userMoney - sodaMachine[2].sodaPrice << " will be returned to you. "; } /* function sodaGrape accepts the sodaData structure array to do the math with and change the quantity of drinks in the machine and the income to set the earned income. will return the array structure at grape soda sub which is 3. */ void sodaGrape(double & income) {
  • 10. //at this point we have to declare a variable to accept the amount //of money being spent on the soda double userMoney; cout << " "; cout << "You have selected Grape Soda to purchase. "; cout << "Please enter in the amount of money you wish to "; cout << "spend on this purchse. "; cout << "Amounts between 0 and $1.00 only are accepted. "; cin >> userMoney; //validation for if the amount entered is negative or greater than $1.00 while (userMoney < 0 || userMoney > 1.0) { cout << " "; cout << "Looks like you didn't do what I asked. "; cout << "Please try again, only this time, only something between "; cout << "0 and $1.00. "; cin >> userMoney; } //not asked for, but it would be hard to sell a soda if there //wasn't enough money for it. while (userMoney < sodaMachine[3].sodaPrice) { cout << " "; cout << "Not enough money "; cout << "Please try again, only this time, only something between "; cout << "0 and $1.00. "; cin >> userMoney; } //now that the money has been verified, time to do a math sodaMachine[3].sodaQuant--; income += sodaMachine[3].sodaPrice; cout << "Given that you supplied more than the cost of the drink, "; cout << "$" << userMoney - sodaMachine[3].sodaPrice << " will be returned to you. "; } /* function sodaCream
  • 11. accepts the sodaData structure array to do the math with and change the quantity of drinks in the machine and the income to set the earned income. will return the array structure at cream soda sub which is 4. */ void sodaCream(double & income) { //at this point we have to declare a variable to accept the amount //of money being spent on the soda double userMoney; cout << " "; cout << "You have selected Cream Soda to purchase. "; cout << "Please enter in the amount of money you wish to "; cout << "spend on this purchse. "; cout << "Amounts between 0 and $1.00 only are accepted. "; cin >> userMoney; //validation for if the amount entered is negative or greater than $1.00 while (userMoney < 0 || userMoney > 1.0) { cout << " "; cout << "Looks like you didn't do what I asked. "; cout << "Please try again, only this time, only something between "; cout << "0 and $1.00. "; cin >> userMoney; } //not asked for, but it would be hard to sell a soda if there //wasn't enough money for it. while (userMoney < sodaMachine[4].sodaPrice) { cout << " "; cout << "Not enough money "; cout << "Please try again, only this time, only something between "; cout << "0 and $1.00. "; cin >> userMoney; } //now that the money has been verified, time to do a math
  • 12. sodaMachine[4].sodaQuant--; income += sodaMachine[4].sodaPrice; cout << "Given that you supplied more than the cost of the drink, "; cout << "$" << userMoney - sodaMachine[4].sodaPrice << " will be returned to you. "; } Solution #include #include #include //to maintain the input for soda #include using namespace std; struct sodaData { string sodaName; double sodaPrice; int sodaQuant; }; const int SIZE = 5; sodaData sodaMachine[SIZE] = { //preloading the array of structures { "COLA", .75, 20 }, //sub 0 { "ROOT BEER", .75, 20 }, //sub 1 { "LEMON-LIME", .75, 20 }, //sub 2 { "GRAPE SODA", .80, 0 }, //sub 3 - this is set to 0 for ease of testing purposes { "CREAM SODA", .80, 20 }, //sub 4 }; //end the array of structures void sodaCola(double &); void sodaRootBeer(double &); void sodaLemon(double &); void sodaGrape(double &); void sodaCream(double &); void getSoda(int &); //this is just to get user input int main() { int userSoda;
  • 13. double earnedIncome = 0; //this is to hold the total earned by the machine char again; //to redo the whole thing int counter = 0; //added this here so it can be used outside of the for loop cout << "Welcome to the Drink Machine Simulator. "; cout << " "; cout << "To begin, we will accept the soda that you wish the purchase. "; cout << " "; do { cout << setprecision(2) << showpoint; cout << setw(12) << "Drink Name" << setw(20) << "Cost in cents" << setw(20) << "Number in Machine "; cout << "---------------------------------------------------------- "; for (counter = 0; counter < 5; counter++) { cout << counter+1 << ". " << setw(12) << sodaMachine[counter].sodaName << setw(18) << sodaMachine[counter].sodaPrice << setw(18) << sodaMachine[counter].sodaQuant << " "; } cout << counter+1 << ". Quit "; getSoda(userSoda); switch (userSoda) { case 1: if (sodaMachine[0].sodaQuant > 0) sodaCola(earnedIncome); else cout << "This beverage appears to be sold out. "; break; case 2: if (sodaMachine[1].sodaQuant > 0) sodaCola(earnedIncome); else cout << "This beverage appears to be sold out. "; break;
  • 14. case 3: if (sodaMachine[2].sodaQuant > 0) sodaLemon(earnedIncome); else cout << "This beverage appears to be sold out. "; break; case 4: if (sodaMachine[3].sodaQuant > 0) sodaGrape(earnedIncome); else cout << "This beverage appears to be sold out. "; break; case 5: if (sodaMachine[4].sodaQuant > 0) sodaCream(earnedIncome); else cout << "This beverage appears to be sold out. "; break; case 6: break; }; cout << " Would you like to purchase another soda? "; cout << "Please enter Y to purchase another beverage. "; cin >> again; } while (toupper(again) == 'Y'); cout << setprecision(3) << showpoint; cout << " "; cout << "We kept a tally of how much money the machine earned "; cout << "as you ran your simulation. "; cout << "The total comes out to: $" << earnedIncome << ". "; cout << " "; system("pause"); return 0; } void getSoda(int & soda) {
  • 15. bool drinkTrue; cout << "Please input the soda to be purchased. "; cout << "Please use the number of the soda. "; cin >> soda; switch (soda) { case 1: drinkTrue = true; break; case 2: drinkTrue = true; break; case 3: drinkTrue = true; break; case 4: drinkTrue = true; break; case 5: drinkTrue = true; break; case 6: drinkTrue = true; break; default: drinkTrue = false; }; while (drinkTrue !=true) { cout << "Looks like you keyed in the wrong thing. Try again. "; cout << "Less fail this time, eh? "; cout << "Please input the soda to be purchased. "; cout << "Please use the number of the soda. "; cin >> soda; switch (soda)
  • 16. { case 1: drinkTrue = true; break; case 2: drinkTrue = true; break; case 3: drinkTrue = true; break; case 4: drinkTrue = true; break; case 5: drinkTrue = true; break; case 6: drinkTrue = true; break; default: drinkTrue = false; }; //test the new input } } void sodaCola(double & income) { double userMoney; cout << " "; cout << "You have selected Cola to purchase. "; cout << "Please enter in the amount of money you wish to "; cout << "spend on this purchse. "; cout << "Amounts between 0 and $1.00 only are accepted. "; cin >> userMoney; while (userMoney < 0 || userMoney > 1.0)
  • 17. { cout << " "; cout << "Looks like you didn't do what I asked. "; cout << "Please try again, only this time, only something between "; cout << "0 and $1.00. "; cin >> userMoney; } while (userMoney < sodaMachine[0].sodaPrice) { cout << " "; cout << "Not enough money "; cout << "Please try again, only this time, only something between "; cout << "0 and $1.00. "; cin >> userMoney; } sodaMachine[0].sodaQuant--; income += sodaMachine[0].sodaPrice; cout << "Given that you supplied more than the cost of the drink, "; cout << "$" << userMoney - sodaMachine[0].sodaPrice << " will be returned to you. "; } void sodaRootBeer(double & income) { double userMoney; cout << " "; cout << "You have selected Root Beer to purchase. "; cout << "Please enter in the amount of money you wish to "; cout << "spend on this purchse. "; cout << "Amounts between 0 and $1.00 only are accepted. "; cin >> userMoney; while (userMoney < 0 || userMoney > 1.0) { cout << " "; cout << "Looks like you didn't do what I asked. "; cout << "Please try again, only this time, only something between "; cout << "0 and $1.00. "; cin >> userMoney;
  • 18. } while (userMoney < sodaMachine[1].sodaPrice) { cout << " "; cout << "Not enough money "; cout << "Please try again, only this time, only something between "; cout << "0 and $1.00. "; cin >> userMoney; } sodaMachine[1].sodaQuant--; income += sodaMachine[1].sodaPrice; cout << "Given that you supplied more than the cost of the drink, "; cout << "$" << userMoney - sodaMachine[1].sodaPrice << " will be returned to you. "; } void sodaLemon(double & income) { double userMoney; cout << " "; cout << "You have selected Lemon-Lime to purchase. "; cout << "Please enter in the amount of money you wish to "; cout << "spend on this purchse. "; cout << "Amounts between 0 and $1.00 only are accepted. "; cin >> userMoney; while (userMoney < 0 || userMoney > 1.0) { cout << " "; cout << "Looks like you didn't do what I asked. "; cout << "Please try again, only this time, only something between "; cout << "0 and $1.00. "; cin >> userMoney; } while (userMoney < sodaMachine[2].sodaPrice) { cout << " "; cout << "Not enough money "; cout << "Please try again, only this time, only something between ";
  • 19. cout << "0 and $1.00. "; cin >> userMoney; } sodaMachine[2].sodaQuant--; income += sodaMachine[2].sodaPrice; cout << "Given that you supplied more than the cost of the drink, "; cout << "$" << userMoney - sodaMachine[2].sodaPrice << " will be returned to you. "; } void sodaGrape(double & income) { double userMoney; cout << " "; cout << "You have selected Grape Soda to purchase. "; cout << "Please enter in the amount of money you wish to "; cout << "spend on this purchse. "; cout << "Amounts between 0 and $1.00 only are accepted. "; cin >> userMoney; //validation for if the amount entered is negative or greater than $1.00 while (userMoney < 0 || userMoney > 1.0) { cout << " "; cout << "Looks like you didn't do what I asked. "; cout << "Please try again, only this time, only something between "; cout << "0 and $1.00. "; cin >> userMoney; } while (userMoney < sodaMachine[3].sodaPrice) { cout << " "; cout << "Not enough money "; cout << "Please try again, only this time, only something between "; cout << "0 and $1.00. "; cin >> userMoney; } sodaMachine[3].sodaQuant--;
  • 20. income += sodaMachine[3].sodaPrice; cout << "Given that you supplied more than the cost of the drink, "; cout << "$" << userMoney - sodaMachine[3].sodaPrice << " will be returned to you. "; } void sodaCream(double & income) { double userMoney; cout << " "; cout << "You have selected Cream Soda to purchase. "; cout << "Please enter in the amount of money you wish to "; cout << "spend on this purchse. "; cout << "Amounts between 0 and $1.00 only are accepted. "; cin >> userMoney; while (userMoney < 0 || userMoney > 1.0) { cout << " "; cout << "Looks like you didn't do what I asked. "; cout << "Please try again, only this time, only something between "; cout << "0 and $1.00. "; cin >> userMoney; } while (userMoney < sodaMachine[4].sodaPrice) { cout << " "; cout << "Not enough money "; cout << "Please try again, only this time, only something between "; cout << "0 and $1.00. "; cin >> userMoney; } sodaMachine[4].sodaQuant--; income += sodaMachine[4].sodaPrice; cout << "Given that you supplied more than the cost of the drink, "; cout << "$" << userMoney - sodaMachine[4].sodaPrice << " will be returned to you. "; }