从金钱转换为票据 [英] Convert from Money to Note

查看:89
本文介绍了从金钱转换为票据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,我的讲师要我编写有关将Money转换为Note的代码,我有187美元,所以它等于1一百美元,1个50美元,1个20美元,1个10美元,1个5美元.请注意,还有2个1美元的note.请帮助我,因为我刚刚学习了2个星期!!!!谢谢!!

My lecturer asked me to write code about converting the Money to Note for example I have 187 dollars so it equals to 1 one hundred dollar note,1 fifty dollars note,1 twenty dollars note,1 ten dollars note,1 five dollars note and 2 one dollars note.Please help me because i''ve just learned this subject for 2 weeks!!!Thanks in advance!!!

推荐答案

我的建议是在考虑如何解决您的想法,然后将其转换为算法.考虑一下您知道是真实的事物(例如可用的纸币面额),然后问自己一些问题.例如,您是否需要用最少数量的纸币来解决该问题,如何存储纸币面额,将使用哪个界面进行输入和输出.另外,考虑一下数学问题.以及您将如何处理用户可能无法达到您期望的情况,例如.进入
My suggestion is to think about how you solved it in your mind, and then translate that into an algorithm. Think about the things you know to be true - like the denomination of notes available to you - and then ask yourself some questions. For example, do you have to solve it with the minimum number of notes, how are you going to store note denominations, what interface will you use for input and output. Also, think about the mathematical issues. And how will you handle the situation where the user may not do what you expect, eg. enters


187.23?

非常好的运动,请告诉我们您的生活如何.如果您有任何特定问题,请发回.祝你好运!
187.23?

Very nice exercise and please tell us how you get on. If you have any specific questions post back. Good luck!


AnnieMacD在上面的回答中为您提供了线索;这只是简单的数学问题.
从最大面额的纸币或硬币开始,查看总计是否大于该面额,如果是,则从总计中减去该纸币的所有值.对每个较低的面额重复此过程,直到总数达到零且过程完成.即使是对新学生,将这种小算法转换为C/C ++代码也不难.
AnnieMacD gave you a clue in her answer above; this is just a question of simple mathematics.
Starting from your largest denomination note or coin see if the total is greater than that denomination, and if so subtract all values of that note from the total. Repeat the process for each denomination lower until your total reaches zero and your process is complete. Converting this small algorithm into C/C++ code should not be difficult even for a new student.


这篇关于从金钱转换为票据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆