C++ Vending Machine program HELP!

Discussion in 'Programming' started by ShadyLady, Mar 6, 2010.

  1. #1
    OK, so I created my program. It works up until the stage where I enter item number.
    Once item number is entered, nothing happens, but it should read out what I have bought and should ask me to enter correct amount and give correct change.
    Below is my code.

    #include <iostream>
    #include <iomanip>                                             
    using namespace std;
    
    
    int main()                                                      
    {
    char money;
    double totalm = 0;
    double value = 0, valued = 0, valuen = 0, valueq = 0, valueb = 0;
    int c1=1, c2=2, c3=3, c4=4, c5=5, c6=6; // item numbers
    int C1=1, C2=2, C3=3, C4=4, C5=5, C6=6;
    int item;
    
    	cout<<"======Vending Machine======"<<endl; 
    	cout<<"    Enter p to purchase a product    "<<endl; // asks for user input
    	cin>>money;
    
    	while(money!='p' && money!='P')
    
    	cout<<"=========Vending Machine========="<<endl; // displays 'vending machine'
    	cout<<"    Snickers     Mars     Haribo        "<<endl;
    	cout<<"     0.60       0.50     1.50         "<<endl;
    	cout<<"       C1          C2        C3          "<<endl<<endl;
    	cout<<"     Twirl       Twix      Lion         "<<endl;
    	cout<<"     0.50       0.70     0.75         "<<endl;
    	cout<<"       C4          C5        C6          "<<endl;
    	cout<<"========================================="<<endl;
    	cout<<"Please enter item number"<<endl; // asks user to enter item number that they wish to purchase
    	cin>>item;
    
    	if (item==c1||C1)
    	{
    		double S=0.60;
    		float change=0;
    		if(totalm>=S)
    		{
    			cout<<"Snickers is purchased"<<endl;
    			change=totalm-S;
    			cout<<"Money deposited is"<<totalm<<"Your change is"<<change<<endl;
    			cout<<"Thank You"<<endl;
    		}
    		else
    		{
    		}
    
    		if (item==c2||C2)
    	{
    		float M=0.50;
    		float change=0;
    		if(totalm>=M)
    		{
    			cout<<"Mars is purchased"<<endl;
    			change=totalm-M;
    			cout<<"Money deposited is"<<totalm<<"Your change is"<<change<<endl;
    			cout<<"Thank You"<<endl;
    		}
    		else
    		{
    		}
    
    			if (item==c3||C3)
    	{
    		float H=1.50;
    		float change=0;
    		if(totalm>=H)
    		{
    			cout<<"Haribo is purchased"<<endl;
    			change=totalm-H;
    			cout<<"Money deposited is"<<totalm<<"Your change is"<<change<<endl;
    			cout<<"Thank You"<<endl;
    		}
    		else
    		{
    		}
    
    			if (item==c4||C4)
    	{
    		float Tw=0.50;
    		float change=0;
    		if(totalm>=Tw)
    		{
    			cout<<"Twirl is purchased"<<endl;
    			change=totalm-Tw;
    			cout<<"Money deposited is"<<totalm<<"Your change is"<<change<<endl;
    			cout<<"Thank You"<<endl;
    		}
    		else
    		{
    		}
    
    			if (item==c5||C5)
    	{
    		float T=0.70;
    		float change=0;
    		if(totalm>=T)
    		{
    			cout<<"Twix is purchased"<<endl;
    			change=totalm-T;
    			cout<<"Money deposited is"<<totalm<<"Your change is"<<change<<endl;
    			cout<<"Thank You"<<endl;
    		}
    		else
    		{
    		}
    
    			if (item==c6||C6)
    	{
    		float L=0.75;
    		float change=0;
    		if(totalm>=L)
    		{
    			cout<<"Lion is purchased"<<endl;
    			change=totalm-L;
    			cout<<"Money deposited is"<<totalm<<"Your change is"<<change<<endl;
    			cout<<"Thank You"<<endl;
    		}
    		else
    		{
    		}
    			}
    			}
    
    		return 0; // terminates successfully 
    			}
    			}
    		}
    	}
    
    }
    
    Code (markup):
    HELP!
     
    ShadyLady, Mar 6, 2010 IP
  2. ShadyLady

    ShadyLady Active Member

    Messages:
    775
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #2
    anyone know a solution?
     
    ShadyLady, Mar 8, 2010 IP