❔ Please help with a ''simple'' cash-register simulator.
I need my program to be able to tell how many 50 cents it will give back to the customer. For example total sum is 99.5, customer pays 100 bill and will get 50 cents back. I've been sitting with this for hours and can't get it to work. Note that i started learning C# this week, and need to have this ready tomorrow. Appreciate any help! A following picture in the comment section of how the program looks.
16 Replies
its missing that it should give ''1'' 50 cent back to the customer.
You're casting
vaxel
to int
, you can't have fractional values (0.5) in as an int
Thanks man, you're a god!
Np
Hey! Would you be able to help with how i would go about rounding a number to nearest 0.5? For example total is 77.26 and it should round to 77.5 And if it's 77.23 it should round to 77.
I'm not really sure how to go about ''Math.Round'', things i've done so far is not working. gives me like, will send pic.
In this case you might want to multiple the value by 100, either before or after doing all bank notes calculations
So in the case of 77.26 and doing it after, you'd be left with 0.26
Multiplying this with 100
Results in 26, you can have your rounding logic round it to 50
If you want to do it before doing an calculations, you'd need to divide by (bank note * 100)
oh man, not sure i understand it 100% but i will try! srry for being a noob.
No worries at all, I think the way I phrased it is a bit confusing...
I'll try to demonstrate it so it makes more sense
Let's say remaining is 15.26
We have 2 bank notes 10 and 5
And a 50 cent coin
First we check how many 10 bank notes we can give back
15.26/10
We get 1
So
$10: 1
Now we do the same to 5 bank note
5.26/5
We get 1
So far
$10: 1
$5: 1
Now for the 0.26 cents, we cant give back 26 cents so we to round it up we multiple it by 100 (so we can operate on it easily instead of using fractions)
0.26*100 = 26
We do some rounding logic (Let's assume we have a rounding method
RoundToFiftyCents
)
Result = RoundToFiftyCents(26)
Result now is 50
We can easily operate on it as an int
now instead of float
, double
or decimal
Thanks for the explanation, i will try! I started learning C# on Monday and i got this assignment today which needs to be done tomorrow. I love the help but at the same time i don't like asking too much. Hopefully I'll get this done today. However it goes thanks man!
Good luck! feel free to ask if you have any more questions
just a question, would it be possible to do this with if, if else, else? Cus in our ''book'' and the pages we were supposed to read, there's nothing about what you have described nor what i found on the internet. So i'm questioning myself, would it work with the if, else if, else cus there's a few examples of that in my book and some ''>'' ''<'', smaller than and greater than examples.
Well, you can use some sort of branching
if
if else
for the rounding logicThanks a lot man! I finally did it and my program is now complete! It only took many many hours... (12h) Hopefully I'll become a decent programmer in the future. And yes I'm happy!
👏 Well done!!!
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.