Sunday, November 11, 2012

vending matchine code in c++


#include<iostream>
#include<iomanip>
#include <ctime>
#include <cstdlib>
using namespace std;
void main()
{
int coin,pepsi=5,fanta=5,water=5,cock=5,sprite=5,choice,timer=0,counter;
char re;
bool over=0;
    timer = clock();
do

{
timer=0;
counter=0;
do
{
system("cls");system("COLOR 2a");
cout<<setw(30)<<"\n\nInsert coin of 5 in Vender Matchine"<<endl;
cin>>coin;
if(coin!=5)
cout<<setw(30)<<"pleas insert 5 ruppes coin only\n";
}
while(coin!=5);

cout<<setw(40)<<"__________________________________________________\n";
cout<<setw(40)<<"|***************--Select your drink--**************|\n";
cout<<setw(34)<<"|Choice NO        Drink            Bottles|        |\n";
cout<<setw(40)<<"|__________________________________________________|\n";
cout<<setw(40)<<"|--------------------------------------------------|"<<endl;
cout<<setw(30)<<"|1:>            Pepsi Bottle        :   "<<pepsi<<setw(11)<<"|"<<endl;
cout<<setw(40)<<"|--------------------------------------------------|"<<endl;
cout<<setw(30)<<"|2:>            Fanta Bottle        :   "<<fanta<<setw(11)<<"|"<<endl;
cout<<setw(40)<<"|--------------------------------------------------"<<"|"<<endl;
cout<<setw(30)<<"|3:>            Sprite Bottle       : "<<sprite<<setw(13)<<"|"<<endl;
cout<<setw(40)<<"|--------------------------------------------------"<<"|"<<endl;
cout<<setw(30)<<"|4:>            Water Bottle        : "<<water<<setw(13)<<"|"<<endl;
cout<<setw(40)<<"|--------------------------------------------------"<<"|"<<endl;
cout<<setw(30)<<"|5:>            Cock Bottle         : "<<cock<<setw(13)<<"|"<<endl;
cout<<setw(40)<<"|--------------------------------------------------|"<<endl;
cout<<setw(40)<<"|__________________________________________________|\n";
//do
//{
cin>>choice;
timer = clock();
if((timer/1000)>30)
{
cout<<setw(30)<<"your time is over 20 second please pick up your coine"<<endl;
coin=0;
}
else
{
if(counter>2)
{
cout<<setw(30)<<"you press invelid key at  two time please pick up your coine\n";
    
coin=0;
break;
}
switch(choice)
{
case 1:
if(pepsi==0)
{
cout<<setw(30)<<"pepsi is not avalibel in stock\n";
cout<<setw(30)<<"enter r if you want return coin\n";
cin>>re;
if(re=='r')
{
cout<<setw(30)<<"pick your coin :"<<5<<"$\n";
coin=0;
}
else
{
cout<<setw(30)<<"Enter your choice for any other bottle\n";
cin>>choice;
}
}
else
{
cout<<setw(30)<<"pick up the pepsi bottle\n";
pepsi--;
}
break;
case 2:
if(fanta==0)
{
cout<<setw(30)<<"fanta is not avalibel in stock\n";
cout<<setw(30)<<"enter r if you want return coin\n";
cin>>re;
if(re=='r')
{
cout<<setw(30)<<"pick your coin :"<<5<<"$\n";
coin=0;
}
else
{
cout<<setw(30)<<"Enter your choice for any other bottle\n";
cin>>choice;
}

}
else
{
cout<<setw(30)<<"pick up the fanta bottle \n";
fanta--;
}
break;
case 3:
if(sprite==0)
{
cout<<setw(30)<<"Sprite is not avalibel in stock\n";
cout<<setw(30)<<"enter r if you want return coin\n";
cin>>re;
if(re=='r')

{
cout<<setw(30)<<"pick your coin :"<<5<<"$\n";
coin=0;
}
else
{
cout<<setw(30)<<"Enter your choice for any other bottle\n";
cin>>choice;

}
}
else
{
cout<<setw(30)<<"pick up the Sprite bottle \n";
sprite--;
}
break;
case 4:
if(re==0)
{
cout<<setw(30)<<"Water buttol is not avalibel in stock\n";
cout<<setw(30)<<"enter r if you want return coin\n";
cin>>re;
if(choice=='r')
{
cout<<setw(30)<<"pick your coin :"<<5<<"$\n";
coin=0;
}
else
{
cout<<setw(30)<<"Enter your choice for any other bottle\n";
cin>>choice;
}
}
else
{
cout<<setw(30)<<"pick up the water bottle \n";
water--;

}
break;
case 5:
if(re==0)
{
cout<<setw(30)<<"Cock is not avalibel in stock\n";

cout<<setw(30)<<"enter r if you want return coin\n";
cin>>re;
if(choice=='r')
{
cout<<setw(30)<<"pick your coin :"<<5<<"$\n";

coin=0;
}
else
{
cout<<setw(30)<<"Enter your choice for any other bottle\n";
cin>>choice;
}
}
else
{
cout<<setw(30)<<"pick up the cock bottle \n";
cock--;
}
break;
default :
{
counter++;
continue;
cout<<setw(30)<<"Invelid selection\n";
}
}
//}while(choice==1 || choice==2 || choice==3 || choice==4 || choice==5);
cout<<setw(30)<<"DO you want turnOff the matchin if yes press y\n";
cin>>re;
if(re=='y' || re=='Y')
break;
}
}while(pepsi!=0 || fanta!=0 || water!=0 || cock!=0 ||sprite!=0);
      system("COLOR 4a");
      
cout<<setw(30)<<"GOOD BYE"<<endl<<endl<<endl;

}