Sie sind auf Seite 1von 6

#include<iostream>

#include<iomanip>
using namespace std;
int quantity(char x, int y);
double totalPrice(char x, int y);
void display(char choice, double money, int quant);
void itemsPriceList(char x);
void items(char x);
void itemsList();
int Quant[8] = {10,10,10,10,10,10,10,10};
int Quantity[8] = {10,10,10,10,10,10,10,10};
int main()
{
int quant;
char choice, ans, opt;
double price, money, change;
system("cls");
cout<<fixed<<showpoint<<setprecision(2);
do
{
cout<<"\n\n\n\t==================Automated Vending Machine================
==";
cout<<"\n\t* Your Options (Beverages):
*";
cout<<"\n\t* A.Soda-Php 25.00
B. Lemonade-Php 15.00
*";
cout<<"\n\t* C.Bottled Water-Php 10.00 D. Energy Drink-Php 35.00
*";
cout<<"\n\t*
*";
cout<<"\n\t* Snacks:
*";
cout<<"\n\t* E. Lays-Php 60.00
F. Piattos-Php 12.00
*";
cout<<"\n\t* G. Cup Noodles-25.00
H. Rock Candy-Php 2.00/pc
*";
cout<<"\n\t*
*";
cout<<"\n\t=============================================================";
cout<<"\n\tEnter your choice : ";
cin>>choice;
cout<<"\n\tEnter your money : ";
cin>>money;
cout<<"\n\tInserted money: "<<money;
cout<<"\n\tYour choice is ";
itemsPriceList(choice);
cout<<"\n\tHow many do you want? ";
cin>>quant;
cout<<endl;
switch(choice)
{
case 'A':
{
if (quant>Quantity[0])
cout<<"Transaction cannot be processed. Remaining stocks: "<<Quantity
[0];
else
display(choice, money, quant);
}

;break;
case 'B':
{
if (quant>Quantity[1])
cout<<"Transaction cannot be processed. Remaining stocks: "<<Quantity
[1];
else
display(choice, money, quant);
}
;break;
case 'C':
{
if (quant>Quantity[2])
cout<<"Transaction cannot be processed. Remaining stocks: "<<Quantity
[2];
else
display(choice, money, quant);
}
;break;
case 'D':
{
if (quant>Quantity[3])
cout<<"Transaction cannot be processed. Remaining stocks: "<<Quantity
[3];
else
display(choice, money, quant);
}
;break;
case 'E':
{
if (quant>Quantity[4])
cout<<"Transaction cannot be processed. Remaining stocks: "<<Quantity
[4];
else
display(choice, money, quant);
}
;break;
case 'F':
{
if (quant>Quantity[5])
cout<<"Transaction cannot be processed. Remaining stocks: "<<Quantity
[5];
else
display(choice, money, quant);
}
;break;
case 'G':
{
if (quant>Quantity[6])
cout<<"Transaction cannot be processed. Remaining stocks: "<<Quantity
[6];
else
display(choice, money, quant);
}
;break;

case 'H':
{
if (quant>Quantity[7])
cout<<"Transaction cannot be processed. Remaining stocks: "<<Quantity
[7];
else
display(choice, money, quant);
}
;break;
}
cout<<"\nPlease try again? (Y/N): ";
cin>>ans;
}while (ans == 'Y');
cin.ignore();cin.ignore();
return 0;
}
void itemsList()
{
cout<<"Soda"<<endl;
cout<<"Lemonade"<<endl;
cout<<"Bottled water"<<endl;
cout<<"Energy Drink"<<endl;
cout<<"Lays"<<endl;
cout<<"Piattos"<<endl;
cout<<"Cup Noodles"<<endl;
cout<<"Rock Candy"<<endl;
}
void items(char x)
{
switch(x)
{
case 'A': cout<<"Soda";;break;
case 'B': cout<<"Lemonade";;break;
case 'C': cout<<"Bottled water";;break;
case 'D': cout<<"Energy Drink";;break;
case 'E': cout<<"Lays";;break;
case 'F': cout<<"Piattos";;break;
case 'G': cout<<"Cup Noodles";;break;
case 'H': cout<<"Rock Candy";;break;
}
}
void itemsPriceList(char x)
{
switch(x)
{
case 'A': cout<<"Soda worth Php 25.00 each."<<endl;;break;
case 'B': cout<<"Lemonade Php 15.00 each."<<endl;;break;
case 'C': cout<<"Bottled water Php 10.00 each."<<endl;;break;
case 'D': cout<<"Energy Drink Php 35.00 each."<<endl;;break;
case 'E': cout<<"Lays Php 60.00"<<endl;;break;
case 'F': cout<<"Piattos Php 12.00"<<endl;;break;

case 'G': cout<<"Cup Noodles Php 25.00"<<endl;;break;


case 'H': cout<<"Rock Candy Php 2.00 /piece"<<endl;;break;
}
}
double totalPrice(char x, int y)
{
switch (x)
{
case 'A': return y*25;;break;
case 'B': return y*15;;break;
case 'C': return y*10;;break;
case 'D': return y*35;;break;
case 'E': return y*60;;break;
case 'F': return y*12;;break;
case 'G': return y*25;;break;
case 'H': return y*2;;break;
}
}
int quantity(char x, int y)
{
switch (x)
{
case 'A':
{
if (y < Quant[0])
return Quant[0] - y;
else
return Quant[0];
};break;
case 'B':
{
if (y < Quant[1])
return Quant[1] - y;
else
return Quant[1];
};break;
case 'C':
{
if (y < Quant[2])
return Quant[2] - y;
else
return Quant[2];
};break;
case 'D':
{
if (y < Quant[3])
return Quant[3] - y;
else
return Quant[3];
};break;
case 'E':
{
if (y < Quant[4])

return Quant[4] - y;
else
return Quant[4];
};break;
case 'F':
{
if (y < Quant[5])
return Quant[5] - y;
else
return Quant[5];
};break;
case 'G':
{
if (y < Quant[6])
return Quant[6] - y;
else
return Quant[6];
};break;
case 'H':
{
if (y < Quant[7])
return Quant[7] - y;
else
return Quant[7];
};break;
}
}
void display(char choice, double money, int quant)
{
double price, change;
switch (choice)
{
case 'A':
{
Quantity[0] = quantity(choice, quant);
price=totalPrice(choice, quant);
}; break;
case 'B':
{
Quantity[1] = quantity(choice, quant);
price=totalPrice(choice, quant);
};break;
case 'C':
{
Quantity[2] = quantity(choice, quant);
price=totalPrice(choice, quant);
};break;
case 'D':
{
Quantity[3] = quantity(choice, quant);
price=totalPrice(choice, quant);

};break;
case 'E':
{
Quantity[4] = quantity(choice, quant);
price=totalPrice(choice, quant);
};break;
case 'F':
{
Quantity[5] = quantity(choice, quant);
price=totalPrice(choice, quant);
};break;
case 'G':
{
Quantity[6] = quantity(choice, quant);
price=totalPrice(choice, quant);
};break;
case 'H':
{
Quantity[7] = quantity(choice, quant);
price=totalPrice(choice, quant);
};break;
}
if (money==price)
{
cout<<"\n\tHere is your " <<quant<<' ';
items(choice);
cout<<" ."<<"\n\tThank you for using our Automated Vending
Machine.";
}
else if (money>price)
{
change=money-price;
cout<<"\n\tYour change is "<< change <<" pesos.";
cout<<"\n\tHere is your "<<quant<<' ';
items(choice);
cout<<" . \n\tThank you for using our Automated Vending Mac
hine.";
}
else
{
cout<<"\n\tYour money is not enough to buy "<<quant<<' ';
items(choice);
}
}

Das könnte Ihnen auch gefallen