需要帮助理解这个c ++问题 [英] Need help understanding this c++ question

查看:70
本文介绍了需要帮助理解这个c ++问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我刚刚开始使用c ++并尝试做一个简单的atm系统,它只允许用户以最少量的笔记退出,但需要花费20美元或50美元。



我试图理解这个问题,它要求我创建两个函数 - 1. bool canDispense(int amt),如果金额可以在组合中返回,则返回true 20秒和50秒,否则返回false,并且2. int dispense50s(int amt)返回50s的数量,这将导致最少数量的笔记被分发..



所以假设在第一季度,如果我得到5张50和2张20的票据,那么在第二季度,这意味着答案是5?

也是在这样的情况下想知道,是吗好的打印出任何输出信息,根据上述问题说明你将获得多少20和50的账单?



我尝试过:



我试过加入int dispense50s函数我nto bool canDispense,但我不确定我是否误解了我的问题..

Hi all, I just started out in c++ and am trying to do a simple atm system where it will only allows user to withdraw with the least amount of notes but in the form of either $20 or $50..

I am trying to understand this question in which it ask me to create two functions - 1. bool canDispense (int amt) where it returns true if the amount can hand out in combination of 20s and 50s and return false otherwise, and 2. int dispense50s(int amt) returns the number of 50s that will result in least number of notes being hand out..

So assuming in Q1, if I got 5 bills of 50 and 2 bills of 20, then in Q2, it will means that the answer is 5?
Also was wondering in cases like this, is it alright to print out any output message that state how many bills of 20s and 50s you will be getting based on the above questions?

What I have tried:

I have tried incorporating the int dispense50s function into bool canDispense, but I am just not sure if I am misunderstanding my question..

推荐答案

20或


50。 。



我试图理解这个问题,它要求我创建两个函数 - 1. bool canDispense(int amt)如果金额可以返回true以20s和50s的组合分发,否则返回false,并且2. int dispense50s(int amt)返回50s的数量,这将导致最少数量的笔记被分发..



因此假设在第一季度,如果我得到5张50和2张20的票据,那么在第二季度,这意味着答案是5?

也是在案例中想知道像这样,根据上述问题,打印出任何输出信息可以说明您将获得多少20和50的账单吗?



我尝试了什么:



我尝试将int dispense50s函数合并到bool canDis中但是,我只是不确定我是否误解了我的问题..
50..

I am trying to understand this question in which it ask me to create two functions - 1. bool canDispense (int amt) where it returns true if the amount can hand out in combination of 20s and 50s and return false otherwise, and 2. int dispense50s(int amt) returns the number of 50s that will result in least number of notes being hand out..

So assuming in Q1, if I got 5 bills of 50 and 2 bills of 20, then in Q2, it will means that the answer is 5?
Also was wondering in cases like this, is it alright to print out any output message that state how many bills of 20s and 50s you will be getting based on the above questions?

What I have tried:

I have tried incorporating the int dispense50s function into bool canDispense, but I am just not sure if I am misunderstanding my question..


Q1可以用20和50个音符分发值



如前所述,可以检查是否可以通过组合注释将值除以余数。如果值是20或50的倍数,或者该值是具有附加条件的10的倍数,则显然是这样。附加条件是大于或等于70的值。为了证明这一点,请写下表:

10 - 否

20 - 1 x 20

30 - 没有

40 - 2 x 20

50 - 1 x 50

60 - 3 x 20

70 - 1 x 50 + 1 x 20

80 - 4 x 20

90 - 1 x 50 + 2 x 20

100 - 2 x 50

110 - 1 x 50 + 3 x 20

120 - 2 x 50 + 1 x 20

130 - 1 x 50 + 4 x 20

140 - 2 x 50 + 2 x 20

...

Q2数量最少总票数50秒



该功能只应返回50秒的数量。但要知道这一点,你还必须知道满足最少总票数要求的20秒数。看看上面的表格,你会发现会有最大值。四个20个音符。因此,您需要编写一个算法来获取输入值的20和50个音符的数量:



  • 检查值是否为倍数50.如果是,则数值除以50
  • 检查值减去20是否是50的倍数。如果是,则数值减去20除以50
  • 检查值是否减去40是50的倍数。如果是这样的数字是值减去40除以50
  • 检查值减去60是50的倍数。如果是这样的数字是值减去60除以50
  • 检查值减去80是否为50的倍数。如果是,则数值减去80除以50
  • 否则返回零(无50注)


这篇关于需要帮助理解这个c ++问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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