| | |
ATM money count
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jan 2009
Posts: 7
Reputation:
Solved Threads: 0
I am all confused, I don't where to start. This is my first programming class and i need some help please.
Write a C program for an automatic teller machine that dispenses money. The user should enter the amount desired (a multiple of 10 dollars) and the machine dispenses this amount using the least number of bills. The bills dispensed are 50s, 20s, and 10s. Write a function that determines how many of each kind of bill to dispense.
Write a C program for an automatic teller machine that dispenses money. The user should enter the amount desired (a multiple of 10 dollars) and the machine dispenses this amount using the least number of bills. The bills dispensed are 50s, 20s, and 10s. Write a function that determines how many of each kind of bill to dispense.
>I am all confused, I don't where to start.
Somewhere, anywhere, even if it's completely wrong. If you have to, write a hello world program and build on it. The last thing you want to do is fall into a hole of not knowing what to do and being afraid to try something.
As a start, write just the I/O. Snip hard parts off of the program requirements until you have something workable to get you started, for example:
This is very simple. All you're doing is taking input and spitting it back out as output. From there you can incrementally add features as you become more comfortable with the program.
Somewhere, anywhere, even if it's completely wrong. If you have to, write a hello world program and build on it. The last thing you want to do is fall into a hole of not knowing what to do and being afraid to try something.
As a start, write just the I/O. Snip hard parts off of the program requirements until you have something workable to get you started, for example:
•
•
•
•
Write a C program for an automatic teller machine that dispenses money. The user should enter the amount desired (a multiple of 10 dollars) and the machine dispenses this amount.
I'm here to prove you wrong.
•
•
Join Date: Jan 2009
Posts: 7
Reputation:
Solved Threads: 0
Is this how the program should begin? i am really lost here
C Syntax (Toggle Plain Text)
/* * Compute the user transactions. */ #include <stdio.h> int main (void) { double amount; double count_amount ; count_amount = 0.0; while (count_amount < amount) { printf("Enter the amount to withdraw >"); scanf("%1f", &count_amount); count_amount = count_amount + 10; return } count_amount = count_amount + 10
Last edited by Narue; Jan 23rd, 2009 at 5:42 pm. Reason: added code tags
•
•
Join Date: May 2008
Posts: 584
Reputation:
Solved Threads: 94
How would you solve the problem manually?
I want to withdraw $180, what bills would you give me?
How did you decide how many to give me?
Ok now make the computer do it...
Write some code that asks how much to withdraw.
Add a print statement that outputs what it thought I entered.
(The last step might be temporary, but its always nice to verify the input works.)
Then write some code to have the computer follow the way you solved the problem by hand.
Add some code to output what you calculated.
I want to withdraw $180, what bills would you give me?
How did you decide how many to give me?
Ok now make the computer do it...
Write some code that asks how much to withdraw.
Add a print statement that outputs what it thought I entered.
(The last step might be temporary, but its always nice to verify the input works.)
Then write some code to have the computer follow the way you solved the problem by hand.
Add some code to output what you calculated.
•
•
Join Date: Jan 2009
Posts: 7
Reputation:
Solved Threads: 0
•
•
•
•
>I am all confused, I don't where to start.
Declare a variable that will keep money amount.
Ask the user for money amount.
Read the input.
Process the input in a function to determined how many bills of each class needs to be outputted.
c Syntax (Toggle Plain Text)
/* * Compute the user transactions. */ #include <stdio.h> int main (void) { int amount; int number_bills; printf("Enter the amount to withdraw >"); scanf("%d", &amount); number_bills=0; while (amount >= 50) { number_bills++; amount -= 50; } printf("Dispense %d $50 bill(s), ",number_bills); number_bills=0; while (amount >= 20) { number_bills++; amount -= 20; } printf("%d $20 bill(s), ",number_bills); number_bills=0; while (amount >= 10) { number_bills++; amount -= 10; } printf("and %d $10 bill(s).\n",number_bills); return 0; }
Last edited by Narue; Jan 25th, 2009 at 9:03 am. Reason: added code tags, but no formatting to begin with
>Write a function that determines how many of each kind of bill to dispense.
What about this part now? Can you take the processing of bills away from main and implement it in a function?
Use code tags to preserver the indentation and format of your code. How? Highlight all your source code, then click the # at the top of the message window. Add a '=c' to the beginning tag like: [CODE=C] to specify that we are dealing with the C language.
What about this part now? Can you take the processing of bills away from main and implement it in a function?
Use code tags to preserver the indentation and format of your code. How? Highlight all your source code, then click the # at the top of the message window. Add a '=c' to the beginning tag like: [CODE=C] to specify that we are dealing with the C language.
![]() |
Other Threads in the C Forum
- Previous Thread: Correction
- Next Thread: Writing a kernel
| Thread Tools | Search this Thread |
#include * ansi append array arrays asterisks binarysearch calculate changingto char character cm convert copyimagefile cprogramme creafecopyofanytypeoffileinc database dynamic execv feet fflush fgets file fork forloop framework function getlasterror givemetehcodez grade gtkwinlinux hacking hardware histogram inches include incrementoperators input intmain() iso kernel keyboard km license linked linkedlist linux list lists locate logical_drives looping loopinsideloop. lowest matrix microsoft motherboard mqqueue number oddnumber odf opendocumentformat opensource overwrite owf pattern pdf performance pointer posix probleminc process program programming radix recursion recv recvblocked research reversing scanf scripting segmentationfault sequential socket socketprograming standard string systemcall testing threads turboc unix user variable voidmain() wab whythiscodecausesegmentationfault windowsapi






