0

Return Values

I'm working on a little code piece just for a bit of practice. I am curious on something however; I wish to setup a strong with variables inside that have return values in them. For Example: I have a random number generator that generates anything between 0 and 100, rounding to the 2nd decimal place(mimicking how money works). I wish to return multiple values with the most efficient payment method to make exact change. If the random number generator generated a number such as 74.57, the return value within a strong would say: "You must pay three $20's, one $10, four $1's, two quarters, one nickel, and 2 pennies. The problem I am having is figuring out how to setup these multiple return values without setting up multiple if else functions over and over again. If there is no other way, then I guess I'll take the tedious route. Looking for any suggestions!

29th Sep 2021, 1:17 PM
Ethan
1 Antwort
+ 2
Quite easily here is a logic for you(if there are money such as (100$, 50$, 20$, 10
lt; 5$): Starting with 74.57 a = 74.5 // 100 74.5 -= 100*a b = 74.5 // 50 74.5 -= 50*b c= 74.5 // 20 74.5 -= 20*c etc... It should be quicker than making tone of if statements...
29th Sep 2021, 2:07 PM
Aleksei Radchenkov
Aleksei Radchenkov - avatar