Code:
#include <iostream>
#include <string>
#include <stdio.h>
using namespace std;
class amount
{
protected:
int Ten_cent_coin;
int Twenty_cent_coin;
double Ten_cent_coin_change;
int Twenty_cent_coin_change;
int amount_coffee;
int amount_tea;
double return_Ten_cent_coin;
int return_Twenty_cent_coin;
};
class choice_and_pay_up: public amount
{
protected:
string Amount_User_Enter;
double total_User_pay;
string text_Coffee_Or_Tea;
string continue_or_not;
string want_milk_or_not;
string End_Or_Not;
double Coffee_Price;
double change;
double remainder;
double return_change;
double ten_cent;
public:
choice_and_pay_up()
{
total_User_pay=0;
Coffee_Price=1;
Ten_cent_coin=15;
Ten_cent_coin_change=0;
Twenty_cent_coin=10;
Twenty_cent_coin_change=0;
amount_coffee=2;
}
void display_amount_CT_left()
{
cout <<"Amount of coffee left is" <<" " << amount_coffee << endl;
}
void ask_user()
{
cout<<"May I know what you want?" << endl;
cout<<"Coffee"<<endl;
cout <<"The price for coffee is $1"<<endl;
cout<<"Please enter coffee: ";
getline(cin, text_Coffee_Or_Tea);
if(text_Coffee_Or_Tea=="coffee")
{
if(amount_coffee == 0)
{
cout <<"Error Error Error!!!" << endl;
cout <<"We don't have any coffee anymore!!!" << endl;
}
Bankai:
cout <<"Please enter only $1, 50 cent, 20 cent and 10 cent coins : ";
getline(cin,Amount_User_Enter);
if(Amount_User_Enter=="50 cent")
total_User_pay=total_User_pay+0.5;
else
if(Amount_User_Enter=="10 cent")
total_User_pay=total_User_pay+0.1;
else
if(Amount_User_Enter=="20 cent")
total_User_pay=total_User_pay+0.2;
else
if(Amount_User_Enter=="1 dollar")
total_User_pay=total_User_pay+1.0;
cout <<"You have inserted $" << total_User_pay << endl;
cout <<"Do you to continue(Press YES) or just press any key " << endl;
getline(cin,continue_or_not);
if(continue_or_not =="YES")
{
goto Bankai;
}
else
if(total_User_pay==1)
{
amount_coffee = amount_coffee - 1;
cout << endl;
cout <<"Here is your drink(coffee)!!!" << endl;
cout <<"Amount of Coffee left is currently : " << amount_coffee << endl;
total_User_pay = 0;
}
}
}
};
void main()
{
string End_Or_Not;
choice_and_pay_up A;
Start_all_over_again:
cout <<"Welcome to my Vending Machine"<<endl;
A.display_amount_CT_left();
cout <<endl;
A.ask_user();
cout << endl;
cout <<"Do you want to continue your order?";
cout <<"Press YES,otherwise,Press any key)"<< endl;
getline(cin,End_Or_Not);
if(End_Or_Not=="YES")
{
cout << endl;
goto Start_all_over_again;
}
}
How my program works?
-Enter coffee , then enter 1 dollar , 50 cent , 20 cent or 10 cent , then if it is equal to 1 dollar , it will display here is your coffee.
My problem:
When I enter 50 cent , 20 cent , 20 cent and 10 cent, by right it is added up to 1 but how come it doesn't display at all.[Here is your coffee]???
However , when I enter 50 cent and 50 cent , or 50 cent , 20 cent , 10 cent and 20 cent , it is able to display the message.
I am suspecting that my 10 cent is having error in my program code somehow but I am not sure where it is.If I enter 10 cent as my last amount , it will never display the message.
Could Anyone please help me solve my problem??/
Bookmarks