The problem here is that I have been asked to use Functions to create the code and i dont really know quite how to do that. Other than "main" im suppose to use a function for cash tendered, menu list, customer choice, and pin entry. Im expected to use constants for the shutdown pin, the cost of food items, and the number of customers who can use the machine before it shuts down. (i think i have that done correctly) My variables will need to be fixed as im expected to use local instead of global but i havent made that change completely because i cant compile and i dont quite get what i should be doing to fix it or get the variables correct. Can anyone offer a bit of guidance as to how to break this up into functions correctly or at least patch the code enough to make it work?
#include <iostream>
#include <iomanip>
usingnamespace std;
constint CUSTOMER = 100;
constint SHUTDOWN = 9110;
constdouble beverage = 5.00;
constdouble candy = 2.25;
constdouble hotdog = 7.00;
constdouble popcorn = 6.75;
constdouble nachos = 4.50;
char getMenu (void);
char getSelection (void);
double getTendered (void);
int getPin (void);
int main()
{
char ch;
int pin, counter = 0;
do
{
system("cls");
pin = getPin();
if (pin==SHUTDOWN)
{break;}
getMenu();
getSelection();
getTendered();
}
while (counter!=CUSTOMER);
cout<<endl;
cout<<"This unit is shutting down to restock"<<endl<<endl;
system("pause");
return 0;
}
char getMenu (void)
{
char ch;
int counter;
do
{
ch = '\n';
system("cls");
cout<<"Please select a Snack\n"
<<"B - Beverage $5.00\n"
<<"C - Candy $2.25\n"
<<"H - Hot Dog $7.00\n"
<<"N - Nachos $4.50\n"
<<"P - Popcorn $6.75\n"
<<"Q - Quit"<<endl;
cin>>ch;
ch = toupper(ch);
}
while (ch!='B' && ch!='C' && ch!='H' && ch!='N' && ch!='P' && ch!='Q');
return ch;
//Q exit hasnt been setup
counter++;
// if (ch == 'Q') {continue;}
}
char getSelection (void)
{
char ch;
double cost;
cout<<"\nYou selected ";
switch(ch)
{
case'B': cout<<"Beverage"<<endl; cost = beverage; break;
case'C': cout<<"Candy"<<endl; cost = candy; break;
case'H': cout<<"Hot Dog"<<endl; cost = hotdog; break;
case'N': cout<<"Nachos"<<endl; cost = nachos; break;
case'P': cout<<"Popcorn"<<endl; cost = popcorn; break;
}
return'Z'; //what am i returning here?
}
double getTendered (void)
{
double cost, tendered, change = 0;
//not returning costs correctlydo
{
cout<<"Please insert "<<cost<<"\nEnter amount tendered ";
cin>>tendered;
cin.clear();
cin.ignore(10,'\n');
cost = cost - tendered;
}
while (cost>0);
cost = (-1 * cost);
if (cost>0)
{
cout<<"Change: "<<cost<<endl;
}
return change;
}
int getPin(void)
{
int pin;
do
{
system("cls");
cout<<"Welcome to the Movie Food System\n";
cout<<endl;
cout<<"Please enter your 4-digit pin code: ";
cin>>pin;
cin.clear();
cin.ignore(10,'\n');
}
while (pin<1000 || pin>9999);
return pin;
}
Still some notes in there but my functions are in place. The calculations dont work. i tried using "continue" but it says it cant use it outside of a loop which confuses me at this point. Anybody know how to fix this bit?
Just a few minor errors if you guys could help out that would be great. All i really need is to figure out where pieces go and how to pass the data that needs passing. If someone could just plug in the pieces and explain it that would be a huge help. Ive read the articles ive been linked to but im still not getting it so much.