Please check this

///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;

public:
void setprices(float p1,float p2, float p3, float p4, float p5, float p6, float p7, float p8,float p9,float p10)
{
price_p1=p1;
price_p2=p2;
price_p3=p3;
price_p4=p4;
price_p5=p5;
price_p6=p6;
price_p7=p7;
price_p8=p8;
price_p9=p9;
price_p10=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;
}

}
break;
}

}
}
}
}
void ShowMainMenu()
{
cout<<"1-Pspsi"<<endl;
cout<<"2-Cocacola"<<endl;
cout<<"3-Cake"<<endl;
cout<<"4-Nogate"<<endl;
cout<<"5-chocolate"<<endl;
cout<<"6-Shipsy"<<endl;
cout<<"7-Juice"<<endl;
cout<<"8-PowerDrink"<<endl;
cout<<"9-Milk"<<endl;
cout<<"10-Coco-juice"<<endl;

}
void buy_again()
{
char answer;
bool buy=false;
cout<<"Do you want to buy again? [Y/N]"<<endl;
cin>>answer;
if(answer=='Y'|| answer=='y')
{
buy=true;
VendingMachine();
}
}
};
int main()
{
float price1,price2,price3,price4,price5,price6,price7,price8,price9,price10;
cout<<"Enter product 1 price"<<endl;
cin>>price1;
cout<<"Enter product 2 price"<<endl;
cin>>price2;
cout<<"Enter product 3 price"<<endl;
cin>>price3;
cout<<"Enter product 4 price"<<endl;
cin>>price4;
cout<<"Enter product 5 price"<<endl;
cin>>price5;
cout<<"Enter product 6 price"<<endl;
cin>>price6;
cout<<"Enter product 7 price"<<endl;
cin>>price7;
cout<<"Enter product 8 price"<<endl;
cin>>price8;
cout<<"Enter product 9 price"<<endl;
cin>>price9;
cout<<"Enter product 10 price"<<endl;
cin>>price10;
VendingMachine v; v.setprices(price1,price2,price3,price4,price5,price6,price7,price8,price9,price10);
v.ShowMainMenu();
v.buy_again();
return 0;
}
doesn't compile
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;

http://www.cplusplus.com/doc/tutorial/arrays/
Topic archived. No new replies allowed.