Foxhateram Posted 24 February 2009 Posted 24 February 2009 i know this should go in the "computer help forum" but no-one looks in there. so i'l put it in here. This is the brief i have been given. I have managed to achieve the desired result using repetitive divisions and subtraction. However how to make the program work while using Arrays and Forms really stumps me. Write a program to prompt the user to input an amount in pence. Your program should then work out the least number of coins needed for this amount of money. The possible coins are £2, £1, 50p, 20p, 10p, 5p, 2p, 1p. For example, the least number of coins for 397 pence is: 1 x £2, 1 x £1, 1 x 50p, 2 x 20p, 1 x 5p, 1 x 2p There could be a significant amount of repetition in parts of your solution. Marks will be awarded for using some sort of data structure (such as an array) to hold the denominations of coins available and the number of coins used, to reduce the amount of repetition. Your program should repeatedly prompt the user for an amount of pence. As long as a positive amount is typed in, the program should calculate the number of coins; when a zero or negative amount is typed in the program should halt. any ideas?
Zingari Posted 24 February 2009 Posted 24 February 2009 gordon brown might be able to help , he's good with money
Monk Posted 24 February 2009 Posted 24 February 2009 I don't know C but I'm a dab hand with VBA. The way I'd do it - Input = x c1 = 200 c2 = 100 c3 = 50 c4 = 20 c5 = 10 c6 = 5 c7 = 2 c8 = 1 if input/c1 > 1 then NumC1 = Int(input/c1) input = input - (NumC1 x c1) then go onto the next coin and do the same. You could use a loop to get through the coin numbers, which you could put in an array. Pretty straightforward. Does that make sense?
Foxhateram Posted 24 February 2009 Author Posted 24 February 2009 I don't know C but I'm a dab hand with VBA.The way I'd do it - Input = x c1 = 200 c2 = 100 c3 = 50 c4 = 20 c5 = 10 c6 = 5 c7 = 2 c8 = 1 if input/c1 > 1 then NumC1 = Int(input/c1) input = input - (NumC1 x c1) then go onto the next coin and do the same. You could use a loop to get through the coin numbers, which you could put in an array. Pretty straightforward. Does that make sense? Thankyou. that makes a lot of sense cheers.
Foxhateram Posted 24 February 2009 Author Posted 24 February 2009 Thankyou. that makes a lot of sense cheers. Error 1 Operator '/' cannot be applied to operands of type 'int' and 'int[]' Any ideas how to fix such a problem?
act smiley Posted 24 February 2009 Posted 24 February 2009 Does c## not use integer division automatically? Try using mod which would be % Alternatively you might be trying to apply it to the array rather than the element of the array.
cisono Posted 25 February 2009 Posted 25 February 2009 Does c## not use integer division automatically? Try using mod which would be %Alternatively you might be trying to apply it to the array rather than the element of the array. It must be Microsoft's idea of strong typing
Foxhateram Posted 25 February 2009 Author Posted 25 February 2009 It must be Microsoft's idea of strong typing Cheers for you help guys. Managed to get it done.
Lillehamring Posted 25 February 2009 Posted 25 February 2009 now i can see why there is a seperate section for this sort of stuff, and why 'no one looks in there'
Monk Posted 25 February 2009 Posted 25 February 2009 Cheers for you help guys. Managed to get it done. Nice one, I wish my job still involved problem solving like this. It used to when I was down at RBS
Recommended Posts
Archived
This topic is now archived and is closed to further replies.