使用c ++的返回值函数和switch语句 [英] Using return value functions and switch statement for c++

查看:105
本文介绍了使用c ++的返回值函数和switch语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想写一个程序来控制巧克力机的动作。显示要询问的信息

需要什么样的巧克力:普通(30p),巴西坚果(35p),豪华(50p)。我们

的选择。然后必须以下列形式请求钱:?请输入30p?

,具体取决于选择。必须显示此消息,直到所需的金额为

输入。如果插入的太多,则应显示一条消息,指示

更改欠款的数量。并且还会显示一条消息指示?感谢您的购买?使用

函数和切换命令。

I want to write a program to control the action of a chocolate machine. Displaying a message to ask
what kind of chocolate is required: Plain (30p), Brazil nut (35p), Luxury (50p). Us
on the choice. Then money must be requested, in the form: ?Please insert 30p ?
depending on the selection. this message must be displayed until the required amount has been
input. If too much has been inserted, then a message indicating the amount of
change owing should be displayed. And also display a message indicating ?Thanks for Buying?. use the
function and switch command.

推荐答案

好的,你是如何开始使用这个程序的?你有没有把它分解成几个步骤?


请请插入30p用这个人插入的钱换?例如,如果他们插入1p,它是否会改为请插入29p。 ?
Alright, how have you started with this program? Have you broken it down into steps?

Does the "Please insert 30p" change with the money that the person has inserted? eg if they insert 1p, does it change to "Please insert 29p" ?


展开 | 选择 | Wrap | 行号


啊,这是一个经典错误。您只需要一个价格变量。而不是3个价格变量,只声明一个。

int price;

然后当你设置它时,设置单个变量:

price1 = 0.30;变成价格= 0.30;

price2 = 0.35;变成价格= 0.35;

price3 = 0.50;变成价格= 0.50;


然后用单一价格调用自动售货机功能。
Ahh, this is a classic error. You only want one price variable. Instead of 3 price variables, declare just one.
int price;
Then when you set it, set the single variable:
price1 = 0.30; becomes price = 0.30;
price2 = 0.35; becomes price = 0.35;
price3 = 0.50; becomes price = 0.50;

Then call the vending function with the single price.


这篇关于使用c ++的返回值函数和switch语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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