Results 1 to 3 of 3

Thread: Problem with Vending machine C++.total_user_pay doesn't add up to 1, when enter 50 cent , 20 cent , 20 cent and 10 cent?

  1. #1
    Join Date
    Aug 2010
    Posts
    2

    Problem with Vending machine C++.total_user_pay doesn't add up to 1, when enter 50 cent , 20 cent , 20 cent and 10 cent?

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

  2. #2
    Join Date
    Nov 2008
    Posts
    1,192

    Re: Problem with Vending machine C++.total_user_pay doesn't add up to 1, when enter 50 cent , 20 cent , 20 cent and 10 cent?

    Couple of suggestions. I think "total_User_pay=0;" is not proper, given in choice_and_pay_up(). Since total_User_pay is double, you should be using 0.0 in place. Next when you are checking what the user has entered (like 50 cent, 20 cent and 10 cent coins etc), you have not provided the default ELSE statement which should be executed if all the other validation fails. Next use COUT after every count to make sure if it "10 cent" that is buggy.

  3. #3
    Join Date
    Aug 2010
    Posts
    2

    Re: Problem with Vending machine C++.total_user_pay doesn't add up to 1, when enter 50 cent , 20 cent , 20 cent and 10 cent?

    Problem solved!!!

Similar Threads

  1. Nfsv4 Timeout error in Cent OS
    By Mykola in forum Networking & Security
    Replies: 6
    Last Post: 08-05-2011, 10:26 AM
  2. favorite 99 cent app
    By Thingy in forum Portable Devices
    Replies: 3
    Last Post: 22-12-2010, 08:32 PM
  3. How to insert a cent symbol in windows 7
    By Cassey in forum Windows Software
    Replies: 4
    Last Post: 02-02-2010, 03:12 AM
  4. Dropped 50 Cent game now published by THQ
    By kattman in forum Video Games
    Replies: 0
    Last Post: 11-10-2008, 01:09 PM
  5. Government to increase DTH FDI from 49 to 74 per cent
    By Amol21 in forum India BroadBand
    Replies: 0
    Last Post: 03-10-2008, 02:30 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,624,980.11057 seconds with 17 queries