Our system detected that your browser is blocking advertisements on our site. Please help support FoxesTalk by disabling any kind of ad blocker while browsing this site. Thank you.
Jump to content
Foxhateram

Anyone good at C#

Recommended Posts

Posted

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?

Posted

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?

Posted
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.

Posted
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?

Posted

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.

Posted
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 :whistle:

Posted

now i can see why there is a seperate section for this sort of stuff, and why 'no one looks in there' :yawn:

Posted
Cheers for you help guys. Managed to get it done.

:chant:

Nice one, I wish my job still involved problem solving like this. It used to when I was down at RBS :(

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...