我如何使用这个if语句。 [英] How do I use this if statement.

查看:92
本文介绍了我如何使用这个if语句。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我一直在试图找出这段代码。我的讲师基本上想要使用此运算符添加到数据属性价格,只要它超过零,如果是,可以添加,但如果价格超出50和1650的范围,它应该保持在它是原创的。请帮忙! :)这就是我到目前为止所做的,我无法弄清楚剩下的。



Hello i've been trying to figure out this code. My instructor basically wants to use this operator to add to the data attribute "price" as long as it's over zero and if it is, it's acceptable to add but then if the price goes out of that range 50 and 1650, it should stay at it's original. Please help! :) This is what i've done till now, i can't figure out the rest.

classdevice& classdevice::operator+(double add)
{
        double original;
        price = original;
	if(add>0)
	{
		price = price + add;
	}
	if(price < 50.0 && price > 1650.0)
        {
        price = original;
        }
}



但是当我在我的主程序中运行它时,对象数组中的所有价格都会变为一个值。我该怎么办? :/



我尝试了什么:



但是当我跑步的时候在我的主要内容中,对象数组中的所有价格都转到一个值。我该怎么办? :/


But when i run it in my main, all the price's in the object array go to one value. What do i do? :/

What I have tried:

But when i run it in my main, all the price's in the object array go to one value. What do i do? :/

推荐答案

if(price < 50.0 && price > 1650.0)



您正在测试价格 out范围,但你的测试是错误的。

价格同时不能低于50且高于1650。你需要 operator。


you are testing for price out of range but your test is wrong.
price can not be lower than 50 and higher than 1650 at the same time. You need to or operator.


这很简单:

It's pretty simple:
double original;
price = original;



那么你定价的价值是多少? :笑:

你想要的是:


So what value do you set price to? :laugh:
What you wanted was:

double original = price;



有了它,它应该可以工作。


With that, it should work.


<br />
double original;<br />
price = original;<br />



一切都以原始设置为默认值0.0

添加是否小于0.0?


Everything starts with original set to the default value of 0.0
Is add ever less than 0.0?


这篇关于我如何使用这个if语句。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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