///this program like a vending machine
///but there is a problem in the price and the input(user) money
///please help!
///run this code and you will understand the main problem
///this is an example for product 1 only,but infact there is 10 products
#include <iostream>
using namespace std;
class VendingMachine
{
private:
int num_products;
int p1_avilable=10;
int p2_avilable=10;
int p3_avilable=10;
int p4_avilable=10;
int p5_avilable=10;
int p6_avilable=10;
int p7_avilable=10;
int p8_avilable=10;
int p9_avilable=10;
int p10_avilable=10;
float price_p1;
float price_p2;
float price_p3;
float price_p4;
float price_p5;
float price_p6;
float price_p7;
float price_p8;
float price_p9;
float price_p10;
VendingMachine()
{
int choise;
cout<<"Enter your choise of the products"<<endl;
cin>>choise;
switch(choise)
{
///---------------------------------------------------------------------///
case 1:
{
int item;
cout<<"Enter number of items you want "<<endl;
cin>>item;
if(p1_avilable>item)
{
///----------------------///
float money;
p1_avilable=p1_avilable-item;
cout<<"Enter your money "<<endl;
cin>>money;
if(price_p1>money)
{
cout<<"You haven't enough money to buy"<<endl;
}
else if(price_p1<money)
{
cout<<"Your exchange money is : "<<money-price_p1<<endl;
cout<<"Have a nice day ^_^ "<<endl;
}
else
{
cout<<"you have not any exchange "<<endl;
cout<<"have a nice day"<<endl;
}
///------------------------///
}
else if (p1_avilable==item)
{
if(p1_avilable>item)
{
float money;
p1_avilable=p1_avilable-item;
cout<<"Enter your money "<<endl;
cin>>money;
if(price_p1>money)
{
cout<<"You haven't enough money to buy"<<endl;
}
else if(price_p1<money)
{
cout<<"Your exchange money is : "<<money-price_p1<<endl;
cout<<"Have a nice day ^_^ "<<endl;
}
else
{
cout<<"you have not any exchange "<<endl;
cout<<"have a nice day"<<endl;
}
}
else if(p1_avilable<item)
{
cout<<"Sorry no items left"<<endl;
}
foo.cpp|121 col 2| error: expected ‘;’ after class definition
foo.cpp|122 col 1| error: expected declaration before ‘}’ token
> run this code and you will understand the main problem
¿why don't simply shows us an example run and describe the problem?
(you are the one asking for help, make a freaking effort)
1 2 3 4 5 6 7 8 9 10
int p1_avilable=10;
int p2_avilable=10;
int p3_avilable=10;
int p4_avilable=10;
int p5_avilable=10;
int p6_avilable=10;
int p7_avilable=10;
int p8_avilable=10;
int p9_avilable=10;
int p10_avilable=10;