Write a program to prompt the user to input an amount in pence. Your program should then work out w

Write a program to prompt the user to input an amount in pence. Your program should then work out what coins are the least number needed for this amount of money. The possible coins are £2, £1, 50p, 20p, 10p, 5p, 2p, 1p.For example, the coins which are the least number for 397 pence are:1 x £2, 1 x £1, 1 x 50p, 2 x 20p, 1 x 5p, 1 x 2pThere 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 求高手解答
2026年09月27日 17:09
有2个网友回答
网友(1):

写一段程序用来提示用户投入一定数量的美分。程序然后在计算出最少需要多少数量的美分,这些硬币可能是£2, £1, 50p, 20p, 10p, 5p, 2p, 1p.

举个例子,397美分至少需要以下数量的硬币:
1 x £2, 1 x £1, 1 x 50p, 2 x 20p, 1 x 5p, 1 x 2p

在你的部分的解决方案中可能存在很多重复性的工作。Marks 则可以用一些数据结构(例如矩阵)来储存硬币的面值和有多少枚硬币的投入来减少重复性的操作。

你的程序应该不断的提示用户美分的数量,只要键入正确数量,程序将计算出硬币的数量。当键入零或者不正确的数量,程序将终止。

好辛苦啊, 给加分吧~~~

网友(2):

你也太抠了把 这么长 也不给 一分悬赏, 还求人帮忙。 关键你也太无视别人的脑力劳动了吧,,
哎, 算了为了让你内疚 哥让你看看啥是活雷锋得了, 不过事后要登报 要给大大的 大大的锦旗,
关于编写用户使用PNECE程序的 一点点攻略:
整个程序必须注意不同类的PENCE最少要用多少个对不同的东东。设定可用的硬币为 £2, £1, 50p, 20p, 10p, 5p, 2p, 1p.
程序方案中将会有大量重复的部分, 区分标识将会授予使用某种数据结构来判定硬币数额和计算硬币的具体数量, 从这里 以用来减少重复的次数 这个我不确定啊到

程序将不断提示使用者PENCE所需数额,,一旦使用者输入数据 程序将自动计算所需硬币数量。当O 或者无效的数据输入后 程序将自动停止。。
大概就这意思,有些部分不是很准确 你自己看看改改吧。