C++ If statements...

Hi, Im just wondering but Im used to doing Sourcemod coding which is C++ but some functions and such work diffrently, like for example with Sourcemod, an if statement would look something like this...

1
2
3
 if(IsClientConnected && IsClientInGame)
{
}


So it would work like that and Im trying to understand how an if statement would work with the base C++ programming?
That is a valid C++ if statement.
what is exactly the error or "something different than usual" of the program that happened?
An if statement in C++ accepts one condition. That condition can be made up of several expressions using the logical AND/ORs (&& and/or ||). Each expression is evaluated and combined with the other expressions using the logical operators.

An expression is typically written like to [/code](a == b)[/code]. This will evaluate to either a true false, depending on if a is equal to be. C++ has made it easier on us when checking boolean expressions. If you want to check to see if (myVariable == true) you can simply write if (myVariable). When a variable (or anything else) exists as an expression, it gets evaluated first (functions are called if they're used, etc.) and then the return value is evaluated (the value returned by the function, etc).

If the value can be expressed as true/false, that is the value the expression returns. If it can be expressed as a number, any non zero number is true, 0 is false. If it's a string, I believe
""
is evaluated as false, everything else is evaluated as true. NULL pointers are false, all other pointers true.

Anything I'm wrong on, please correct me.
Ahh thanks a lot, I just needed to understand how it worked. So basicly atm Im trying to do something like this..

1
2
3
 cout << "Hello, enter your password" << endl;
           if(cin == "hello1234") { cout << "Password accepted!" << endl; }
           else { cout << "Incorrect password! Try again." << endl; return(1); }             


I mean would something like that be correct? Basicly I want to make it so that the Client input is equal to the password hello1234, so when they type in hello1234 it should come up with "Password accepted!" but if the password is not equal to that, it should say Incorrect password? Please correct me if this is wrong, thanks.
No, that isn't a valid if statement.

You'd need something like:
1
2
3
4
5
6
7
8
9
string pass;

cout << "Hello, enter your password" << endl;
cin >> pass;  // Assuming password contains no spaces

if (pass == "hello1234")
{
   // Your code here
}
Ah thanks a lot dude :)
Topic archived. No new replies allowed.