User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 402,024 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,398 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Views: 10873 | Replies: 11
Reply
Join Date: Jun 2004
Posts: 1
Reputation: phish1429 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
phish1429 phish1429 is offline Offline
Newbie Poster

Help Vending Machine

  #1  
Jun 17th, 2004
Yes i know everyone hates homework help but this was a last place i could go I am writing a program that stimulates a vending machine and i have written almost all of the code its just not working correctly I am stressing out because it is due by tomorrow and was wondering if anyone would be able to help me out in any way possible i have attached the *.cpp file and would be willing to do anything if someone would look over it Im not asking for you to completly due it just help me becase i am stuck and do not know were to turn.
In the program it is to give change back which i am having trouble doing so because it breaks it down into half dollars dollars dimes quarters and nickles its really the only problem i have i have written code that i believed to work but it has not if anyone is out there please help
This is what the outcome should look like http://www.cs.ua.edu/114/Summer2004/Programs/prog2.htm
Attached Files
File Type: cpp azar_thomas.cpp (2.4 KB, 137 views)
AddThis Social Bookmark Button
Reply With Quote  
Join Date: May 2004
Posts: 250
Reputation: FireNet will become famous soon enough FireNet will become famous soon enough 
Rep Power: 6
Solved Threads: 6
FireNet's Avatar
FireNet FireNet is offline Offline
Posting Whiz in Training

Re: Vending Machine

  #2  
Jun 18th, 2004
Gee, you sure were in a hurry but the lack of full stops really mangles what you say.

This is not really a place to ask for homework answers.But I did look at your code and you use a lot of variables like a,b,c etc for what resonable puprose I cant guess.Also code is a bit messed up in the sense that it too packed where you calculate the vals so I could not understant it too much either.

But here's something :
Lesson1:Code clearly and use spaces and newlines.They will save your life when it comes to debugging.Noodle code is a death trap.(Your code is not too noodlely except in the if else part).

Lesson 2:Use funtions (I dont know if you know funtions)

Now your prob:One Idea would be to convert the entire amount in to the lowest denomintions availble(nickle?) and calulate using that.In the end convert it back to dollars and show what ever remanins as nickles.Dont bother with quaters unless you have to.
Not much but i could not understand you code nor what was you prob,nor do i have a compiler handy right now. :0
See what you can, remember what you need

Fourzon | Earn via Coding
Reply With Quote  
Join Date: Jun 2004
Posts: 34
Reputation: Fili is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 0
Fili's Avatar
Fili Fili is offline Offline
Light Poster

Re: Vending Machine

  #3  
Jun 19th, 2004
I'm writing your program though it might be too late!
Reply With Quote  
Join Date: Jun 2004
Posts: 34
Reputation: Fili is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 0
Fili's Avatar
Fili Fili is offline Offline
Light Poster

Solution Re: Vending Machine

  #4  
Jun 19th, 2004
ok... it's ready but it doesn't cover the part where the option is invalid

#include <iostream.h>
#include <conio.h>
int dol,cen;
unsigned int cb=0,ch;
void convert(int cb)
{
     dol=0;cen=0;
     while (cb>=100) {
		     cb-=100;
		     dol++;
		    }
     cen=cb;
}

void read()
{
		convert(cb);
		cout <<"The current balance is\t" <<dol << " dollars and "<< cen <<" cents "<<endl;
		cout <<"Please choose from one of these options"<<endl;
		cout <<"\n";

		cout <<"5 -	Deposit a nickle\t";
		cout <<"45 -	Buy some gum for 45 cents"<<endl;

		cout <<"10 -	Deposit a dime\t"<<"\t";
		cout <<"55 -	Buy crackers for 55 cents"<<endl;

		cout <<"25 -	Deposit a quarter\t";
		cout <<"60 -	Buy a soft drink for 60 cents"<<endl;

		cout <<"50 -	Deposit a half dollar\t";
		cout <<"70 -	Buy a candy bar for 70 cents"<<endl;

		cout <<"100 -	Deposit a dollar bill\t";
		cout <<"85 -	Buy some chips for 85 cents"<<endl;

		cout <<"0 -	Request coin return and quit\t";

		cout <<"\n";

		cout << "\n" <<"Enter a number to choose an option:\t";
		cin >> ch;
}
void main()
{
       clrscr();
       cout <<"This program simulates a vending machine"<<endl;
       read();
       while (ch!=0)
		{
		 cout<<"\n\n";
		 if (ch==5) { cb+=5;ch=-1;}
		 if (ch==10){ cb+=10;ch=-1;}
		 if (ch==25) {cb+=25;ch=-1;}
		 if (ch==50) {cb+=50;ch=-1;}
		 if (ch==100) {cb+=100;ch=-1;}

		 if (ch==0)
			{
			 cout<<"Quiting\n";
			 while (cb%100==0&&cb>0) {cout<<"Returning a dollar\n";cb-=100;}
			 while (cb%50==0&&cb>0) {cout<<"Returning a half dollar\n";cb-=50;}
			 while (cb%25==0&&cb>0) {cout<<"Returning a quarter\n";cb-=25;}
			 while (cb%10==0&&cb>0) {cout<<"Returning a dinme\n";cb-=10;}
			 while (cb%5==0&&cb>0) {cout<<"Returning a nickel\n";cb-=5;}
			 ch=-1;
			}

		 if (ch==45)
			{
			if (cb>45) {
				    cout<<"Here is your gum\n";
				    cb-=45;
				   }
				else cout<<"Error:Deposit more money\n";
			ch=-1;}
		 if (ch==55)
		 {
			if (cb>55) {
				    cout<<"Here are your crackers\n";
				    cb-=55;
				   }
				else cout<<"Error:Deposit more money\n";
			ch=-1;}
		 if (ch==60)
			{
			if (cb>60) {
				    cout<<"Here is your soft drink\n";
				    cb-=60;
				   }
				else cout<<"Error:Deposit more money\n";
			ch=-1;}
		 if (ch==70)
			{
			if (cb>70) {
				    cout<<"Here is your candy bar\n";
				    cb-=70;
				   }
				else cout<<"Error:Deposit more money\n";
			ch=-1;}
		 if (ch==85)
			{
			if (cb>85) {
				    cout<<"Here are your chips\n";
				    cb-=85;
				   }
				else cout<<"Error:Deposit more money\n";
			ch=-1;}
		read();
       }
       cout << "GoodBye\n";
}
:cheesy:
Reply With Quote  
Join Date: May 2004
Posts: 250
Reputation: FireNet will become famous soon enough FireNet will become famous soon enough 
Rep Power: 6
Solved Threads: 6
FireNet's Avatar
FireNet FireNet is offline Offline
Posting Whiz in Training

Re: Vending Machine

  #5  
Jun 19th, 2004
Quite nice,Fili
See what you can, remember what you need

Fourzon | Earn via Coding
Reply With Quote  
Join Date: Jun 2004
Posts: 34
Reputation: Fili is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 0
Fili's Avatar
Fili Fili is offline Offline
Light Poster

Re: Vending Machine

  #6  
Jun 19th, 2004
Thanks Fire Net Do you suppose it's too late for it to be of any use?
Reply With Quote  
Join Date: May 2004
Posts: 250
Reputation: FireNet will become famous soon enough FireNet will become famous soon enough 
Rep Power: 6
Solved Threads: 6
FireNet's Avatar
FireNet FireNet is offline Offline
Posting Whiz in Training

Re: Vending Machine

  #7  
Jun 19th, 2004
I dont think so,it will be of some use to someone,hey teachers usally accept a submission even if it a bit late.
See what you can, remember what you need

Fourzon | Earn via Coding
Reply With Quote  
Join Date: May 2004
Location: London UK
Posts: 11
Reputation: MaxC is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 0
MaxC MaxC is offline Offline
Newbie Poster

Re: Vending Machine

  #8  
Jun 19th, 2004
Originally Posted by FireNet
I dont think so,it will be of some use to someone

Thank you :cheesy:
MSVC++
Reply With Quote  
Join Date: Jun 2004
Posts: 3
Reputation: MtBobcat is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
MtBobcat MtBobcat is offline Offline
Newbie Poster

Re: Vending Machine

  #9  
Jun 20th, 2004
I'm not expert but I did programming in my 2 year course just finished and understood that vending machines work on the weight of coins.

:rolleyes:
Reply With Quote  
Join Date: Jun 2004
Posts: 34
Reputation: Fili is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 0
Fili's Avatar
Fili Fili is offline Offline
Light Poster

Re: Vending Machine

  #10  
Jun 20th, 2004
Originally Posted by MtBobcat
I'm not expert but I did programming in my 2 year course just finished and understood that vending machines work on the weight of coins.

:rolleyes:

Well, that's what his problem said. Anyway i'm not a US or UK citizen so i'm not great at english What is a vending machine exactly?! :o
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 10:10 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC