“条件总是错误的”题 [英] "Condition is Always False" Question

查看:53
本文介绍了“条件总是错误的”题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的应用程序使用Borland C ++ Builder 5。当我构建我的

应用程序时,它声明我有几个if语句将

总是假的。这些陈述看起来是正确的,所以有人可以告诉我C ++ Builder如何认为

条件总是假的。见下文。谢谢。


< snip>

td.expMon = trk2 [9] * 10 + trk2 [10];


// Borland说这总是假的,虽然条件是好的。
罚款。

if((td.expMon< 0)||(td。 exp)12)){

err = TKT_INVALID_MONTH;

}

< / snip>


< snip>

td.expDay = trk2 [11] * 10 + trk2 [12];


// Borland说这总是假的,虽然条件是

罚款。

if((td.expDay< 0)||(td.expDay 31)){

err = TKT_INVALID_DAY;

}

< / snip>


< snip>

td.eftvDay = trk2 [28] * 10 + trk2 [29];

// Borland说这总是假的,虽然条件是

罚款。

if((td.eftvDay< 0)||(td.eftvDay 31)){

err = TKT_INVALID_DAY;

}

< / snip>

解决方案

Brian写道:


我正在为我的应用程序使用Borland C ++ Builder 5。当我构建我的

应用程序时,它声明我有几个if语句将

总是假的。这些陈述看起来是正确的,所以有人可以告诉我C ++ Builder如何认为

条件总是假的。见下文。谢谢。



见下文。


>

< snip>

td.expMon = trk2 [9] * 10 + trk2 [10];


// Borland说这总是假的,尽管条件是

罚款。

if((td.expMon< 0)||(td.expMon 12)){



''expMon''的类型是什么?如果它是未签名的,则它不能少于
那么0,所以第一个表达式总是假的。


err = TKT_INVALID_MONTH;

}

< / snip>


< snip>

td.expDay = trk2 [11] * 10 + trk2 [12];


// Borland说这总是假的,不过条件是

罚款。

if((td.expDay< 0)||(td.expDay 31)){



此处相同。怎么''expDay''宣布?如果它是未签名的,则不能将
小于0,因此第一个条件将始终为false。


err = TKT_INVALID_DAY ;

}

< / snip>


< snip>

td.eftvDay = trk2 [28] * 10 + trk2 [29];

// Borland说这总是假的,虽然条件是

罚款。

if((td.eftvDay< 0)||(td.eftvDay 31)){



此处相同。


err = TKT_INVALID_DAY;

}

< / snip>



HTH


V

-

请删除资本''A'在通过电子邮件回复时

我没有回复最热门的回复,请不要问


< BLOCKQUOTE>"布赖恩" < bw ****** @ gmail.comwrote in news:1171290076.470125.49620

@ q2g2000cwa.googlegroups.com:


我在我的应用程序中使用Borland C ++ Builder 5。当我构建我的

应用程序时,它声明我有几个if语句将

总是假的。这些陈述看起来是正确的,所以有人可以告诉我C ++ Builder如何认为

条件总是假的。见下文。谢谢。


< snip>

td.expMon = trk2 [9] * 10 + trk2 [10];


// Borland说这总是假的,虽然条件是好的。
罚款。

if((td.expMon< 0)||(td。 exp)12)){

err = TKT_INVALID_MONTH;

}

< / snip>


< snip>

td.expDay = trk2 [11] * 10 + trk2 [12];


// Borland说这总是假的,虽然条件是

罚款。

if((td.expDay< 0)||(td.expDay 31)){

err = TKT_INVALID_DAY;

}

< / snip>


< snip>

td.eftvDay = trk2 [28] * 10 + trk2 [29];

// Borland说这总是假的,虽然条件是

罚款。

if((td.eftvDay< 0)||(td.eftvDay 31)){

err = TKT_INVALID_DAY;

}

< / snip>



我们不是读者......你还没告诉我们什么类型的expMon,

expDay或者eftwDay。但我的第一个猜测是它们都是某种无符号类型的所有元素,因此你所有的<< 0"比较将

总是假的。


2月12日上午9:29,Andre Kostur< nntps ... @ kostur.netwrote :


" Brian" < bwilk ... @ gmail.comwrote in news:1171290076.470125.49620

@ q2g2000cwa.googlegroups.com:


我正在为我的应用程序使用Borland C ++ Builder 5。当我构建我的

应用程序时,它声明我有几个if语句将

总是假的。这些陈述看起来是正确的,所以有人可以告诉我C ++ Builder如何认为

条件总是假的。见下文。谢谢。


< snip>

td.expMon = trk2 [9] * 10 + trk2 [10];


// Borland说这总是假的,虽然条件是

罚款。

if((td.expMon< 0)||(td.expMon 12)){

err = TKT_INVALID_MONTH;

}

< /剪断>


< snip>

td.expDay = trk2 [11] * 10 + trk2 [12];


// Borland说这总是假的,虽然条件是

罚款。

if((td.expDay< 0)||(td.expDay 31)){

err = TKT_INVALID_DAY;

}

< /剪断>


< snip>

td.eftvDay = trk2 [28] * 10 + trk2 [29];

// Borland说这总是假的,虽然条件是

罚款。

if((td.eftvDay< 0)||( td.eftvDay 31)){

err = TKT_INVALID_DAY;

}

< / snip>



我们不是读者......你还没告诉我们什么类型的expMon,

expDay或者eftwDay。但我的第一个猜测是它们都是某种无符号类型的所有元素,因此你所有的<< 0"比较将

总是假的.-隐藏引用的文字 -


- 显示引用的文字 -



好的,是的,就是这样。他们都很好。现在总有意义

。下次我问一个问题时,我会更好地澄清。


I am using Borland C++ Builder 5 for my application. When I build my
application, it states that I have several if-statements that will
always be false. The statements appear correct, so could someone
please enlighten me as to how C++ Builder may think that the
conditions will always be false. See below. Thanks.

<snip>
td.expMon = trk2[9] * 10 + trk2[10];

// Borland says this is always false, though the condition is
fine.
if ((td.expMon < 0) || (td.expMon 12)) {
err = TKT_INVALID_MONTH;
}
</snip>

<snip>
td.expDay = trk2[11] * 10 + trk2[12];

// Borland says this is always false, though the condition is
fine.
if ((td.expDay < 0) || (td.expDay 31)) {
err = TKT_INVALID_DAY;
}
</snip>

<snip>
td.eftvDay = trk2[28] * 10 + trk2[29];
// Borland says this is always false, though the condition is
fine.
if ((td.eftvDay < 0) || (td.eftvDay 31)) {
err = TKT_INVALID_DAY;
}
</snip>

解决方案

Brian wrote:

I am using Borland C++ Builder 5 for my application. When I build my
application, it states that I have several if-statements that will
always be false. The statements appear correct, so could someone
please enlighten me as to how C++ Builder may think that the
conditions will always be false. See below. Thanks.

See below.

>
<snip>
td.expMon = trk2[9] * 10 + trk2[10];

// Borland says this is always false, though the condition is
fine.
if ((td.expMon < 0) || (td.expMon 12)) {

What''s the type of ''expMon''? If it''s unsigned, it cannot be less
that 0, so the first expression is always false.

err = TKT_INVALID_MONTH;
}
</snip>

<snip>
td.expDay = trk2[11] * 10 + trk2[12];

// Borland says this is always false, though the condition is
fine.
if ((td.expDay < 0) || (td.expDay 31)) {

Same here. How is ''expDay'' declared? If it''s unsigned, it cannot
be less than 0, so the first condition will always be false.

err = TKT_INVALID_DAY;
}
</snip>

<snip>
td.eftvDay = trk2[28] * 10 + trk2[29];
// Borland says this is always false, though the condition is
fine.
if ((td.eftvDay < 0) || (td.eftvDay 31)) {

Same here.

err = TKT_INVALID_DAY;
}
</snip>

HTH

V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask


"Brian" <bw******@gmail.comwrote in news:1171290076.470125.49620
@q2g2000cwa.googlegroups.com:

I am using Borland C++ Builder 5 for my application. When I build my
application, it states that I have several if-statements that will
always be false. The statements appear correct, so could someone
please enlighten me as to how C++ Builder may think that the
conditions will always be false. See below. Thanks.

<snip>
td.expMon = trk2[9] * 10 + trk2[10];

// Borland says this is always false, though the condition is
fine.
if ((td.expMon < 0) || (td.expMon 12)) {
err = TKT_INVALID_MONTH;
}
</snip>

<snip>
td.expDay = trk2[11] * 10 + trk2[12];

// Borland says this is always false, though the condition is
fine.
if ((td.expDay < 0) || (td.expDay 31)) {
err = TKT_INVALID_DAY;
}
</snip>

<snip>
td.eftvDay = trk2[28] * 10 + trk2[29];
// Borland says this is always false, though the condition is
fine.
if ((td.eftvDay < 0) || (td.eftvDay 31)) {
err = TKT_INVALID_DAY;
}
</snip>

We''re not mind-readers.... you haven''t told us what the types of expMon,
expDay, or eftwDay are. But my first guess would be that they are all
of some sort of unsigned type, thus all of your "< 0" comparisions will
always be false.


On Feb 12, 9:29 am, Andre Kostur <nntps...@kostur.netwrote:

"Brian" <bwilk...@gmail.comwrote in news:1171290076.470125.49620
@q2g2000cwa.googlegroups.com:


I am using Borland C++ Builder 5 for my application. When I build my
application, it states that I have several if-statements that will
always be false. The statements appear correct, so could someone
please enlighten me as to how C++ Builder may think that the
conditions will always be false. See below. Thanks.

<snip>
td.expMon = trk2[9] * 10 + trk2[10];

// Borland says this is always false, though the condition is
fine.
if ((td.expMon < 0) || (td.expMon 12)) {
err = TKT_INVALID_MONTH;
}
</snip>

<snip>
td.expDay = trk2[11] * 10 + trk2[12];

// Borland says this is always false, though the condition is
fine.
if ((td.expDay < 0) || (td.expDay 31)) {
err = TKT_INVALID_DAY;
}
</snip>

<snip>
td.eftvDay = trk2[28] * 10 + trk2[29];
// Borland says this is always false, though the condition is
fine.
if ((td.eftvDay < 0) || (td.eftvDay 31)) {
err = TKT_INVALID_DAY;
}
</snip>


We''re not mind-readers.... you haven''t told us what the types of expMon,
expDay, or eftwDay are. But my first guess would be that they are all
of some sort of unsigned type, thus all of your "< 0" comparisions will
always be false.- Hide quoted text -

- Show quoted text -

Ok, yep that is what it was. They are all ushort. Makes total sense
now. I''ll clarify better next time I ask a question.


这篇关于“条件总是错误的”题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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