C ++ if语句 - 只有最后一个是真的 [英] C++ if statements - only last one is ever true

查看:73
本文介绍了C ++ if语句 - 只有最后一个是真的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

小组,


如果之前有人问过这个问题,请提前道歉,但我没有能够从谷歌那里得到任何东西档案 - 我一整天都在获得

C ++入门指南。


我正在用Visual C ++ 6 SP5编写程序。

我的代码有很多如果陈述 - 确切地说是19。

如果if语句是真的(技术上,应该只有一个是真实的),程序需要继续if语句。

如果if语句为真,则每个if语句为字符/字符串赋予特定字符串值

数组。


不幸的是,我遇到的问题是只有我的第19条if语句才是真正的b $ b。无论我对我的

变量做出什么改变,其余的都不会成真。


我知道使用一个大的开关在这里是合适的,但是可以使用带浮动的开关作为条件吗?当我使用它时,我的Visual C ++编译器没有像它那样。


对于这么多问题抱歉......任何帮助都会受到赞赏。


谢谢!

Hi group,

Apologies in advance if this has been asked somewhere before, but I haven''t
managed to get anything from the Google archives - I''ve been getting
introductory guides to C++ all day long.

I am writing a program in Visual C++ 6 SP5.
My code has a lot of "if" statements - 19 to be exact.
If the if statements are true (technically, there should only be one that is
ever true), the program needs to continue on after the if statements.
Each if statement assigns a particular string value to a character/string
array if the if statement is true.

Unfortunately, I have the problem whereby only my 19th if statement is ever
true. The rest never become true no matter what changes I make to my
variables.

I know using one big "switch" would be appropriate here, but is it possible
to use switch with a float as its condition? My Visual C++ compiler didn''t
like it when I used that.

Apologies for so many questions... any help would be appreciated.

Thanks!

推荐答案

文章< bt *********** *@ID-193745.news.uni-berlin.de> ;,

" root" < AE *** @ despammed.com>写道:
In article <bt************@ID-193745.news.uni-berlin.de>,
"root" <ae***@despammed.com> wrote:
嗨组,

如果之前有人问过这个问题,请提前道歉,但我还没有设法得到任何东西来自Google档案 - 我整天都在获得C ++入门指南。

我正在用Visual C ++ 6 SP5编写一个程序。
我的代码有一个很多如果语句 - 确切地说是19。
如果if语句是真的(从技术上讲,应该只有一个是真的),程序需要在if语句之后继续。
如果if语句为真,则每个if语句都会为字符/字符串
数组分配一个特定的字符串值。

不幸的是,我遇到的问题是只有我的第19个if语句才是
真的。无论我对变量做出什么改变,其余的都不会成真。

我知道使用一个大的开关。在这里是合适的,但是可以使用带有浮子的开关作为其条件吗?当我使用它时,我的Visual C ++编译器并不喜欢它。

为这么多问题道歉...任何帮助都将不胜感激。

谢谢!
Hi group,

Apologies in advance if this has been asked somewhere before, but I haven''t
managed to get anything from the Google archives - I''ve been getting
introductory guides to C++ all day long.

I am writing a program in Visual C++ 6 SP5.
My code has a lot of "if" statements - 19 to be exact.
If the if statements are true (technically, there should only be one that is
ever true), the program needs to continue on after the if statements.
Each if statement assigns a particular string value to a character/string
array if the if statement is true.

Unfortunately, I have the problem whereby only my 19th if statement is ever
true. The rest never become true no matter what changes I make to my
variables.

I know using one big "switch" would be appropriate here, but is it possible
to use switch with a float as its condition? My Visual C++ compiler didn''t
like it when I used that.

Apologies for so many questions... any help would be appreciated.

Thanks!




虽然我无法确定,因为你对这些if语句的条件相当模糊

正在检查是否,这对我来说听起来好像你试图测试浮点值是否相等,这是

a大禁忌。退房:

http://www.parashift.com/c++-faq-lit...html#faq-29.17



Although I can''t be sure, as your were rather vague about what the
conditions these if statements are checking for are, it sounds to me
like you''re trying to test floating point values for equality, which is
a big no-no. Check out:

http://www.parashift.com/c++-faq-lit...html#faq-29.17


root写道:
root wrote:
嗨小组,

如果之前有人问过这个问题,请提前道歉,但我还没有设法从Google档案 - 我整天都在获取C ++入门指南。

我正在用Visual C ++ 6 SP5编写程序。
我的代码有很多"如果"语句 - 确切地说是19。
如果if语句是真的(从技术上讲,应该只有一个是真的),程序需要在if语句之后继续。
如果if语句为真,则每个if语句都会为字符/字符串
数组分配一个特定的字符串值。

不幸的是,我遇到的问题是只有我的第19个if语句才是
真的。无论我对变量做出什么改变,其余的都不会成真。

我知道使用一个大的开关。在这里是合适的,但是可以使用带有浮子的开关作为其条件吗?当我使用它时,我的Visual C ++编译器并不喜欢它。

为这么多问题道歉...任何帮助都将不胜感激。

谢谢!
Hi group,

Apologies in advance if this has been asked somewhere before, but I haven''t
managed to get anything from the Google archives - I''ve been getting
introductory guides to C++ all day long.

I am writing a program in Visual C++ 6 SP5.
My code has a lot of "if" statements - 19 to be exact.
If the if statements are true (technically, there should only be one that is
ever true), the program needs to continue on after the if statements.
Each if statement assigns a particular string value to a character/string
array if the if statement is true.

Unfortunately, I have the problem whereby only my 19th if statement is ever
true. The rest never become true no matter what changes I make to my
variables.

I know using one big "switch" would be appropriate here, but is it possible
to use switch with a float as its condition? My Visual C++ compiler didn''t
like it when I used that.

Apologies for so many questions... any help would be appreciated.

Thanks!



Hello无名海报,


如果没有看到您的代码我们就无法帮助您,所以请尽量减少

问题并在此处发布您的代码。


-

问候,

Christof Krueger


Hello nameless poster,

we can''t help you without seeing your code, so please try to minimize
the problem and post your code here.

--
Regards,
Christof Krueger


" root" < AE *** @ despammed.com>在消息中写道

news:bt ************ @ ID-193745.news.uni-berlin.de
"root" <ae***@despammed.com> wrote in message
news:bt************@ID-193745.news.uni-berlin.de
嗨组,

如果之前有人问过这个问题,请提前道歉,但我没有从谷歌档案中获得任何东西 - 我已经获得了入门指南C ++整天。

我正在用Visual C ++ 6 SP5编写程序。
我的代码有很多如果语句 - 确切地说是19。
如果if语句是真的(从技术上讲,应该只有一个是真的),程序需要在if
语句之后继续。
如果if语句为true,每个if语句都会为
字符/字符串数组分配一个特定的字符串值。

不幸的是,我遇到的问题是只有我的第19条if语句<永远都是如此。无论我对变量做出什么改变,其余部分都不会成为现实。


您的代码中显然有错误。

我知道使用一个大的开关在这里是合适的,但是可以使用带浮动的开关作为条件吗?
Hi group,

Apologies in advance if this has been asked somewhere before, but I
haven''t managed to get anything from the Google archives - I''ve been
getting introductory guides to C++ all day long.

I am writing a program in Visual C++ 6 SP5.
My code has a lot of "if" statements - 19 to be exact.
If the if statements are true (technically, there should only be one
that is ever true), the program needs to continue on after the if
statements.
Each if statement assigns a particular string value to a
character/string array if the if statement is true.

Unfortunately, I have the problem whereby only my 19th if statement
is ever true. The rest never become true no matter what changes I
make to my variables.

You obviously have a bug in your code.
I know using one big "switch" would be appropriate here, but is it
possible to use switch with a float as its condition?




不,不是。


发布你的代码(可编译形式),这里的人会


1.找到错误。

2.可能建议一个更优雅的解决方案。

-

John Carson

1.要回复电子邮件地址,请删除donald

2.不要回复电子邮件地址(在此处发帖)



No it isn''t.

Post your code (in compileable form) and people here will

1. Find the bug.
2. Possibly suggest a more elegant solution.
--
John Carson
1. To reply to email address, remove donald
2. Don''t reply to email address (post here instead)


这篇关于C ++ if语句 - 只有最后一个是真的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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