Hello! I am trying to do an assignment that requires me to use functions. In the second option "Display Total Daily Sale" I want to obtain the total amount of money from option one "Purchase Drink(s)" and place it inside but I cannot find a way to do so. Any help at all will be appreciated, thank you!
#include <iostream>
usingnamespace std;
void purchaseDrinks();
void dailyTotal();
int main()
{
int selection, password;
cout<<" ~Welcome to Sport Drink Menu~ \n ~Please selection and option below~"<<endl;
cout<<" ------------------------------------"<<endl;
cout<<" 1) Purchase Drink(s) \n 2) Display Total Daily Sale \n 3) End Program"<<endl;
cin>>selection;
if(selection==1){purchaseDrinks();}
if(selection==2){dailyTotal();}
else cout<<"Thank you for using Sport Drink Menu! ";
return 0;
}
void purchaseDrinks()
{
int total, drinkSize, amount;
cout<<" ~Which size?~ "<<endl;
cout<<"--------------------------------"<<endl;
cout<<" 1)Small\n 2)Medium\n 3)Large"<<endl;
cin>>drinkSize;
while(drinkSize<1 || drinkSize>3)
{
cout<<" Please enter valid option."<<endl;
cout<<" ~Which size?~ "<<endl;
cout<<"--------------------------------"<<endl;
cout<<" 1)Small\n 2)Medium\n 3)Large"<<endl;
cin>>drinkSize;
}
cout<<endl;
switch(drinkSize)
{
case 1:
cout<<" How many small drinks will you be purchasing? "<<endl;
cin>>amount;
total= amount*10;
break;
case 2:
cout<<" How many medium drinks will you be purchasing? "<<endl;
cin>>amount;
total = amount*15;
break;
case 3:
cout<<" How many large drinks will you be purchasing? "<<endl;
cin>>amount;
total = amount*18;
break;
}
cout<<" Your total is : $"<<total;
cout<<" Thank you for using Sport Drink Menu! ";
}
void dailyTotal()
{
int password;
cout<<" Enter Password :";
cin>>password;
if(password !=7319)
{
for(int i=0; i<3; i++)
{
cout<<" Access Denied. "<<3-i<<" Attempts Remaining"<<endl;
cin>>password;
}
cout<<" LOCKED ";
}
//cout<<"test"; // cout<<" Total Daily Purchase : $"<<total somehow?
}
#include <iostream>
usingnamespace std;
int total = 0; //Global variable
void purchaseDrinks();
void dailyTotal();
int main()
{
int selection, password;
cout<<" ~Welcome to Sport Drink Menu~ \n ~Please selection and option below~"<<endl;
cout<<" ------------------------------------"<<endl;
cout<<" 1) Purchase Drink(s) \n 2) Display Total Daily Sale \n 3) End Program"<<endl;
cin>>selection;
if(selection==1){purchaseDrinks();}
if(selection==2){dailyTotal();}
else cout<<"Thank you for using Sport Drink Menu! ";
return 0;
}
void purchaseDrinks()
{
int drinkSize, amount;
cout<<" ~Which size?~ "<<endl;
cout<<"--------------------------------"<<endl;
cout<<" 1)Small\n 2)Medium\n 3)Large"<<endl;
cin>>drinkSize;
while(drinkSize<1 || drinkSize>3)
{
cout<<" Please enter valid option."<<endl;
cout<<" ~Which size?~ "<<endl;
cout<<"--------------------------------"<<endl;
cout<<" 1)Small\n 2)Medium\n 3)Large"<<endl;
cin>>drinkSize;
}
cout<<endl;
switch(drinkSize)
{
case 1:
cout<<" How many small drinks will you be purchasing? "<<endl;
cin>>amount;
total= amount*10;
break;
case 2:
cout<<" How many medium drinks will you be purchasing? "<<endl;
cin>>amount;
total = amount*15;
break;
case 3:
cout<<" How many large drinks will you be purchasing? "<<endl;
cin>>amount;
total = amount*18;
break;
}
else
cout<<" Your total is : $"<<total;
cout<<" Thank you for using Sport Drink Menu! ";
}
void dailyTotal()
{
int password;
cout<<" Enter Password :";
cin>>password;
if(password !=7319)
{
for(int i=0; i<3; i++)
{
cout<<" Access Denied. "<<3-i<<" Attempts Remaining"<<endl;
cin>>password;
}
cout<<" LOCKED ";
}
else
cout << "Total: " << total << endl;
}
#include <iostream>
usingnamespace std;
class Store
{
public:
void purchaseDrinks();
void dailyTotal();
private:
int total;
};
int main()
{
int selection, password;
Store store;
cout<<" ~Welcome to Sport Drink Menu~ \n ~Please selection and option below~"<<endl;
cout<<" ------------------------------------"<<endl;
cout<<" 1) Purchase Drink(s) \n 2) Display Total Daily Sale \n 3) End Program"<<endl;
cin>>selection;
if(selection==1){store.purchaseDrinks();}
if(selection==2){store.dailyTotal();}
else cout<<"Thank you for using Sport Drink Menu! ";
return 0;
}
void Store::purchaseDrinks()
{
int drinkSize, amount;
cout<<" ~Which size?~ "<<endl;
cout<<"--------------------------------"<<endl;
cout<<" 1)Small\n 2)Medium\n 3)Large"<<endl;
cin>>drinkSize;
while(drinkSize<1 || drinkSize>3)
{
cout<<" Please enter valid option."<<endl;
cout<<" ~Which size?~ "<<endl;
cout<<"--------------------------------"<<endl;
cout<<" 1)Small\n 2)Medium\n 3)Large"<<endl;
cin>>drinkSize;
}
cout<<endl;
switch(drinkSize)
{
case 1:
cout<<" How many small drinks will you be purchasing? "<<endl;
cin>>amount;
total= amount*10;
break;
case 2:
cout<<" How many medium drinks will you be purchasing? "<<endl;
cin>>amount;
total = amount*15;
break;
case 3:
cout<<" How many large drinks will you be purchasing? "<<endl;
cin>>amount;
total = amount*18;
break;
}
cout<<" Your total is : $"<<total;
cout<<" Thank you for using Sport Drink Menu! ";
}
void Store::dailyTotal()
{
int password;
cout<<" Enter Password :";
cin>>password;
if(password !=7319)
{
for(int i=0; i<3; i++)
{
cout<<" Access Denied. "<<3-i<<" Attempts Remaining"<<endl;
cin>>password;
}
cout<<" LOCKED ";
}
cout<<"Total: " << total << endl;
}