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);
el.
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. ";
}