Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



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?

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 22-08-2010
Member
 
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??/

Reply With Quote
  #2  
Old 23-08-2010
Member
 
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.
Reply With Quote
  #3  
Old 23-08-2010
Member
 
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!!!
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "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?"
Thread Thread Starter Forum Replies Last Post
Nfsv4 Timeout error in Cent OS Mykola Networking & Security 6 08-05-2011 10:26 AM
favorite 99 cent app Thingy Portable Devices 3 22-12-2010 07:32 PM
How to insert a cent symbol in windows 7 Cassey Windows Software 4 02-02-2010 02:12 AM
Dropped 50 Cent game now published by THQ kattman Video Games 0 11-10-2008 01:09 PM
Government to increase DTH FDI from 49 to 74 per cent Amol21 India BroadBand 0 03-10-2008 02:30 PM


All times are GMT +5.5. The time now is 01:49 AM.