Need help on the code for vending machine

anyone can guide me on this code , this code seems like not functioning =(


#include <iostream>
#include <string>
#include <cstdlib>
using namespace std ;

double sodaprc = 0.80 , orangeprc = 1.00 ,lycheeprc = 1.40 ;
string status ;
int sd = 5 , org = 4 , lyc = 3 ;
char choice ;
string display ;
double price, pay, balance;
int changes , amounta , amountb , amountc ,amountd ,amounte ;
string control = "Y" ;

int main()
{

while(control == "Y" || control == "y")
{
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);

cout << "a) MMU Soda " << sodaprc << status << endl ;
cout << "b) MMU Orange " << orangeprc << status << endl ;
cout << "c) MMU Lychee " << lycheeprc << status << endl << endl ;

cout << "Purchase (a to c) => " ;
cin >> choice ;
system ("cls") ;

double price = 0;

switch( choice )
{
case 'a' :
{
status = " " ;
sd = sd - 1 ;
price = sodaprc ;
display = " MMU SODA " ;

if ( sd == 0)
{
status = "[SOLD OUT]";
cout << "Do you want to continue ? " << endl ;
cin >> control ;
}
break ;
}

case 'b' :
{
status = " " ;
org = org - 1 ;
price = orangeprc ;
display = " MMU Orange " ;

if ( org == 0 )
{
status = "[SOLD OUT]";
cout << "Do you want to continue ?" << endl ;
cin >> control ;
}
break ;
}
case 'c' :
{
status = " " ;
lyc = lyc - 1 ;
price = lycheeprc ;
display = " MMU Lychee " ;

if ( lyc == 0 )
{
status = "[SOLD OUT]";
cout << "Do you want to continue ?" << endl ;
cin >> control ;
}
break ;
}
default :
{
cout << "Invalid Input" <<endl ;
cout << "Do you want to continue ?" << endl ;
cin >> control ;
}
}

double pay = 0 ;
double balance = 0 ;

while( pay < price )
{
cout << "Purchase of " << display <<" " << price << endl;
cout << "Amount paid " << pay << endl << endl;
cout << "Insert" << endl;
cout << "a) RM 5" << endl;
cout << "b) RM 1" << endl;
cout << "c) RM 0.50" << endl;
cout << "d) RM 0.20" << endl;
cout << "e) RM 0.10" << endl << endl;
cout <<"Pay ( a to e )=> ";
cin >> choice ;


switch(choice)
{
case 'a' :
{
pay = pay + 5 ;
break ;
}
case 'b' :
{
pay = pay + 1 ;
break ;
}
case 'c' :
{
pay = pay + 0.5 ;
break ;
}
case 'd' :
{
pay = pay + 0.2 ;
break ;
}
case 'e' :
{
pay = pay + 0.1 ;
break ;
}
default :
{
cout << "Invalid Input" << endl ;
cout << "Do you want to continue ? " << endl ;
cin >> control ;

}

}

system ("cls") ;
}

while( pay > price )
{

balance = pay - price ;

for (amounta = 0; balance >= 5.00; amounta++)
{
balance -= 5.00;
}
for (amountb = 0; balance >= 1.00; amountb++)
{
balance -= 1.00;
}
for (amountc = 0; balance >= 0.50; amountc++)
{
balance -= 0.50;
}
for (amountd = 0; balance >= 0.20; amountd++)
{
balance -= 0.20;
}
for (amounte = 0; balance >= 0.00; amounte++)
{
balance -= 0.10;
}


cout << " Cash dispensed" << endl;
cout << " RM 5 X " << amounta << endl;
cout << " RM 1 X " << amountb << endl;
cout << " RM 0.50 X " << amountc << endl;
cout << " RM 0.20 X " << amountd << endl;
cout << " RM 0.10 X " << amounte <<endl;

}

cout << endl;
cout << "Do you want to continue?(Y/N)";
cin >> control ;
cout << endl ;
system("cls");

}

return 0;
}
Last edited on
Oh that's easy, you forgot to read this page: http://www.cplusplus.com/forum/beginner/1/
Topic archived. No new replies allowed.