- Joined
- May 12, 2009
- Messages
- 5,196 (0.95/day)
System Name | Dust Collector |
---|---|
Processor | AMD Ryzen 5 3600X |
Motherboard | Asus B550I Aorus Pro WiFi AX |
Cooling | Alpenfohn Black Ridge V2 w/ Noctua NF-A9x14 |
Memory | Corsair Vengeance LPX 16GB DDR4 3200MHz/CL16 |
Video Card(s) | Power Color Red Dragon RX 5700 XT |
Storage | Samsung EVO+ 500GB NVMe |
Display(s) | Dell S2721DGF |
Case | Dan Case A4 |
Power Supply | Corsair SF600 Platinum |
Mouse | Logitech G603 |
Keyboard | Logitech G613 |
I've been working on this problem for an hour...
And this is where I'm stuck:
(define (minCoins x)
(+ (quotient x 25)
(quotient (remainder x 25) 10)))
This will give me the proper result if I put in any amount of cents that only require quarters and dimes. I've tried going further with nickels but nothing seems to work.
My latest attempt is:
(define (minCoins x)
(+ (quotient x 25)
(quotient (remainder x 25) 10)
(quotient (remainder (quotient (remainder x 25) 10) 5))
))
Logically it makes sense to me but it doesn't seem to work. I'll be frank, I'm terrible at this coding stuff and this is my second time taking the course because I flunked the first time. I just don't get this stuff at all!
Help would be nice!
Edit: Just tried
(define (minCoins x)
(+ (quotient x 25)
(quotient (remainder x 25) 10)
(quotient (remainder x 10) 5)))
Code:
Write the function (minCoins cents) that reports the minimum number
of coins required to make the amount cents. Assume cents is a nonnegative
integer and the only coins available are : quarters, dimes, nickels,
and pennies.
Test Cases:
(minCoins 5) -> 1
(minCoins 26) -> 2
(minCoins 31) -> 3
(minCoins 4) -> 4
(minCoins 118) -> 9
And this is where I'm stuck:
(define (minCoins x)
(+ (quotient x 25)
(quotient (remainder x 25) 10)))
This will give me the proper result if I put in any amount of cents that only require quarters and dimes. I've tried going further with nickels but nothing seems to work.
My latest attempt is:
(define (minCoins x)
(+ (quotient x 25)
(quotient (remainder x 25) 10)
(quotient (remainder (quotient (remainder x 25) 10) 5))
))
Logically it makes sense to me but it doesn't seem to work. I'll be frank, I'm terrible at this coding stuff and this is my second time taking the course because I flunked the first time. I just don't get this stuff at all!
Help would be nice!
Edit: Just tried
(define (minCoins x)
(+ (quotient x 25)
(quotient (remainder x 25) 10)
(quotient (remainder x 10) 5)))
Last edited: