-
June 10th, 2009, 02:25 PM
#1
If Statement && Help
I need help with something, probably simple...
I want to have an "If (something AND something) then....."
but when I try using && I get errors...
Here's what I tried (basically)
Code:
if (GetAsyncKeyState(VK_F8) && x > 1) {
action... }
Thanks for any help.
-
June 10th, 2009, 02:34 PM
#2
Re: If Statement && Help
My crystalball broke down last week... ordered a new one, but I'm still waiting for it. So, while I'm waiting for my new crystalball, maybe you could tell us which errors you get, because right now, I can't read your mind.
-
June 10th, 2009, 02:51 PM
#3
Re: If Statement && Help
Originally Posted by Skizmo
My crystalball broke down last week... ordered a new one, but I'm still waiting for it. So, while I'm waiting for my new crystalball, maybe you could tell us which errors you get, because right now, I can't read your mind.
Lol, well I figured that someone would be able to give an example of what the if statement would look like...
I'm getting errors for different things because of how I wrote the code out, kind'a badly, but either way, could you give a small example of using an if statement with the "&&" and I can use that to make my own. I don't want someone to do it for me, like tell me what code I need, I'm trying to learn how to do everything by myself so I wont need a lot of help in the future...
Thanks.
-
June 10th, 2009, 02:58 PM
#4
Re: If Statement && Help
if (GetAsyncKeyState(VK_F8) && x > 1)
is this supposed to be:
if ( (GetAsyncKeyState(VK_F8) && x ) > 1)
or
if (GetAsyncKeyState(VK_F8) && (x > 1) )
Compiler probably doesn't know? You have two evaluations there.
-
June 10th, 2009, 03:05 PM
#5
Re: If Statement && Help
Originally Posted by KingTermite
is this supposed to be:
if ( (GetAsyncKeyState(VK_F8) && x ) > 1)
or
if (GetAsyncKeyState(VK_F8) && (x > 1) )
Compiler probably doesn't know? You have two evaluations there.
Thanks to you, I got it... I needed an extra pair of () around it...
Here's what worked.
[code]if ((GetAsyncKeyState(VK_F8)) && z > 1)]/code]
Thanks for helping.
-
June 10th, 2009, 03:21 PM
#6
Re: If Statement && Help
Other than you changed x to z, there's no reason adding the extra parenthesis would have any effect on compilation or execution. They're superfluous in that case. Something else changed as well.
-
June 10th, 2009, 03:44 PM
#7
Re: If Statement && Help
Originally Posted by GCDEF
Other than you changed x to z, there's no reason adding the extra parenthesis would have any effect on compilation or execution. They're superfluous in that case. Something else changed as well.
Idk, I'm using Visual C++ Express 2008 and that's all I had to change for it to work. And I just copied and pasted that time, because the variable in there was z, I just used x when I typed it here. Anyways, I don't know why if that ain't the reason, but I did it in 10 different spots, and having the extra () around it got rid of all the errors.
-
June 10th, 2009, 03:47 PM
#8
Re: If Statement && Help
Originally Posted by GCDEF
Other than you changed x to z, there's no reason adding the extra parenthesis would have any effect on compilation or execution. They're superfluous in that case. Something else changed as well.
I agree. I don't understand why they would have made a difference where you put them.
-
June 10th, 2009, 04:19 PM
#9
Re: If Statement && Help
Originally Posted by KingTermite
I agree. I don't understand why they would have made a difference where you put them.
Maybe it's because I have so many if's inside one another? Not sure, but it says I don't have an if for an else if I don't have the extra (). Either way, as long as it works lol.
-
June 10th, 2009, 05:54 PM
#10
Re: If Statement && Help
Originally Posted by Tesujin
Either way, as long as it works lol.
Not knowing "why" it works is almost as bad as it not working, IMO.
-
June 10th, 2009, 06:00 PM
#11
Re: If Statement && Help
Originally Posted by KingTermite
Not knowing "why" it works is almost as bad as it not working, IMO.
Yeah but it seems like it makes sense to me... i mean..
((getkey(vkf8)) && (z > 1))
1. beginning of whole thing
2. beginning of getasynckey
3. beginning of key
4. close key
5. close getasynckey
6. open z>1
7. close z>1
8. close whole thing
thats what it seemed like to me... sorry if im wrong..
-
June 10th, 2009, 07:33 PM
#12
Re: If Statement && Help
Originally Posted by Tesujin
Maybe it's because I have so many if's inside one another? Not sure, but it says I don't have an if for an else if I don't have the extra (). Either way, as long as it works lol.
May be while you were adding those unneeded parenthesis, you accidentally fixed some mismatched ones?
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio:
FeinWindows - replacement windows manager for Visual Studio, and more...
-
June 10th, 2009, 08:19 PM
#13
Re: If Statement && Help
Originally Posted by VladimirF
May be while you were adding those unneeded parenthesis, you accidentally fixed some mismatched ones?
But if that was the case, I would have gotten errors before adding the extra &&'s to the if statement. Also, I added opening and closing parenthesis, so wouldn't the unmatched ones still be there?
-
June 10th, 2009, 08:25 PM
#14
Re: If Statement && Help
Originally Posted by Tesujin
But if that was the case, I would have gotten errors before adding the extra &&'s to the if statement. Also, I added opening and closing parenthesis, so wouldn't the unmatched ones still be there?
I know you think that fixed it, but it didn't. Those extra parenthesis don't do anything in this case. There was something else.
-
June 11th, 2009, 09:14 AM
#15
Re: If Statement && Help
This statement in post #11
Code:
((getkey(vkf8)) && (z > 1))
is not the same as this one in post #5
Code:
if((GetAsyncKeyState(VK_F8)) && z > 1)
I'm guessing you went with the former?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|