I just need some suggestions on how to start this program I wanted to work on for practice.
I want to make a cash register program that gives change and only works with $1's, $5's, $10's, and $20's (I might add cents in later for more practice).
Change should always be made with the largest available denominations.
Here's an example of the output I want it to do.
Do you think Python or Java would be easier to do this in? I was also thinking about AWK or Bash? I am a beginner in all these languages.
I would use what you are most comfortable in, or even use this as practice for writing in them all. The key thing to get you logic documented so you can then write the code without having to think of the whole thing at the same time.
I would suggest that you write down a process using a flow chart or structure diagram that you would use manually and keep refining each step to more and more detail, including loops and conditions, to (for instance) try a $5 and work out how much is still required, loop round and try another $5 if you have one etc.
One question that you will need to answer for yourself is "How are you planning to store the cash?" Are you thinking of simple variables, arrays or even using a file perhaps?
I suppose convention might suggest putting the largest value denomination first, so your input/output would be in the form of twenties, tens, fives and ones, i.e.:-
I hope that this gives you a bit of a steer. Let us know how you get on. If you get stuck on specific coding, paste it to the thread and we will see if someone can help.
You might want to start with how do you make change. You can use a floor or truncate function with division to tell how much of a certain currency you will give as change. Subtract the value of that currency from the change that needs to be given and continue on with the next lower currency until you get to cents. Which is where you stop. So if you owe $61.97 in change see what steps you need to follow to give proper change. With SQL I would do the following:
At this point multiply by 100 for the number of pennies. Once you know the method of figuring out change, then figure out what language you can code it in. You might try Perl or Python this. You can use an array or set of arrays to store the currency and the proper order to do the computation with.
This User Gave Thanks to gandolf989 For This Post:
Eventhough BASH is my currently my most favorite language, for (possibly) 'real' applications, specialy when it comes with numbers handling as in do math, i would choose something else... like python.
AFAIK, awk is no programing language, but a 'streaming/parsing' tool.
(simple said)
Me quite confused by your syntax.
There is:
But there is also
To me this looks like you want to do 2 things at once, while the programing itself, would might be logical, think of what the cashier must do to enter this syntax!
Usualy the chashiers just type in the amount of cash the items costs, and the 'added up' amount the buyer pays. They do NOT count every single piece of cash, and enter 2x5$ 1x10$, 3x20$, etc...
They simply type: 78$ cost -> 80$ paid, returns -> 2$ returns.
I agree, it WOULD be a nice-to-have feature, but for the cashier its very unpractical to count the cash (not the value) each and every time, all day long, when there are 50 people at the register waiting..
Get my point?
In the end, a cash register is more like a big calculator, sure, it contains cash, but in the end, it just sums up the values, and not the counts of cash-items.
That is done at the evenings, manualy. (unless they have a cash counter- another device)
So my only suggestion is to make the syntax simpler.
Change only: VALUE
Pay: COST GIVEN
-> Returns: return/change
So you would only need to catch 2 arguments.
However, if you plan to do this as a 'backend', as in you then could make the GUI having fields to enter the amount of every single cash-item, which then, if there is something within the text field, pass this value as optional value to the script.
As in:
Pay: -twenty 1 -five 1 COST(22) paid(sumy up the textfield=25)
Returns: Return 3
(since there were optionas passed, show) Flow: +10 +5 -2 -1
While the italic text would be generated by the GUI, since there were only 2 (optional) textfield filled)
Hope this helps
EDIT:
Alternativly, you could expect:
Pay: COST / GIVEN
And simply split up the GIVEN to a possiblity of cash combinations.
Thanks guys for all your suggestions. I decided to use Python and I am really stuck. I started to create classes but I am not sure if I even have to. I am not that great in programming and I want to know if I am starting this correctly.
Here is what I am attempting to do for my first two commands:
-init amt = ones [fives [tens [twenties]]]
-Initialize drawer, using counts of bills provided
-If a drawer already exists, this will overwrite it.
-purchase price = amount_tendered
-price
-Integer
-amount_tendered
-Number and type of bills given to register
-amt = ones [fives [tens [twenties]]], where amounts are integers, counts
-Output will be a single line, if successful:
-change returned , where change returned has the same format: ones fives tens twenties
Example output for first two commands:
So do I make the classes and implement the commands? Then in main() just take the user input and call the functions?
You could have two classes and keep transactions separated.
Class CashRegister
An accounting of the bills/coins that should be in your drawer.
date
ones = 1;
fives = 5;
tens = 10;
twenties = 20;
coins...
def bills - add/subtract
def coins - add/subtract
def report
Class Transaction
Keeping track of bills/coins recieved for each exchange.
record
transaction_id
date
sale_amount
tendered_amount
change_amount
tender
bills
coins
change
bills
coins
def update register
def calculate change
Figure out the largest bills/coins to give as change amount.
Update the register.
---------
To start (instantiate) a transaction you would give each a unique name -- something like...
tx1 = Transaction()
call the methods using the new instance name.. tx1.method(param)
...and then append them to a list txList.append(tx1)
Do the register the same way... regToday = CashRegister()
You could have two classes and keep transactions separated.
Class CashRegister
An accounting of the bills/coins that should be in your drawer.
date
ones = 1;
fives = 5;
tens = 10;
twenties = 20;
coins...
def bills - add/subtract
def coins - add/subtract
def report
Class Transaction
Keeping track of bills/coins recieved for each exchange.
record
transaction_id
date
sale_amount
tendered_amount
change_amount
tender
bills
coins
change
bills
coins
def update register
def calculate change
Figure out the largest bills/coins to give as change amount.
Update the register.
---------
To start (instantiate) a transaction you would give each a unique name -- something like...
tx1 = Transaction()
call the methods using the new instance name.. tx1.method(param)
...and then append them to a list txList.append(tx1)
Do the register the same way... regToday = CashRegister()
Thank you! That helps a lot, but is how I started correct? And did I do the syntax correctly?
Hi,
There is a process ( built in C/C++) which starts with my user id and I need to execute a specific function with a different user id. Is there any api so that I provide userid, passwd and the next instance the process will have the new user id privileges.
- Pranav (3 Replies)
Hi everyone, I have an issue with a project of mine. I have to run a program on a terminal which requires to be logged in as su to have it run it. Given that I'm having problem to use expect to give the password I'd like to change the privilege of that program from SU to normal user ( I have the SU... (13 Replies)
Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
1. The problem statement, all variables and given/known data:
I need to create a simple ATM (Cash machine simulation in unix) which shows a welcome screen, then a login screen... (2 Replies)
I need to create a simple ATM (Cash machine simulation in unix) which shows a welcome screen, then a login screen to enter 3 users details. help please on the coding
The users details need to be in a txt file: the details are: (PIN No, First name last name, Account number, Balance, Histrosy)
... (1 Reply)
I am very new at programming and this is probably an easy question, but I am desperate. I need to change this low level code into a C program that I can run so I can print out every "A" that appears with the fork() command. You help is greatly appreciated.
PRINT A
p=fork()
if( p == 0) {... (0 Replies)
How can i find( or list) contents of all registers being used by my program?
Is there any system call or library available for this?:confused:
At runtime in my c/c++ program. At runtime using may be some assembly hack!!!!!!!!!!! (2 Replies)
hi,
Somebody have or known where i can find a perl small perl program to change the password.
The point: First it verify is the user exist, checking the old typed password and replace it with new. The passwords must be encoded.
Thanks, very much! (0 Replies)
I am an IT auditor with a big 4 accounting firm and am cur the process of conducting an application program change audit for a large public company related to Sarbanes Oxley. This is my first time using this forum and need some assistance in verifying a fact that I believe to be true.
My client... (1 Reply)