if statement

Dec 11, 2010 at 6:36pm
How do I use the cin >> function with the if statement?
Dec 11, 2010 at 6:51pm
First of all , you read about using cin. http://www.cplusplus.com/reference/iostream/cin/
Than, you read about using the if statement. http://www.intap.net/~drw/cpp/cpp04_02.htm
Than , you use cin (which by the way is an object, not a function) with the if statement.
Dec 11, 2010 at 9:41pm
operator>> is a function ;^)
Additional links:
http://www.cplusplus.com/doc/tutorial/basic_io/#cin
http://www.cplusplus.com/doc/tutorial/control/#if
http://www.cplusplus.com/articles/how_to_ask/

if ( cin >> variable ) will evaluate true when the input is read successfully ( if this is what you are asking )
Dec 12, 2010 at 12:57am

//this is for single if statement

cin >> variable;
if (condition base on the input variable)

//the code to be executed if the condition is met

statement;


//for the multi if statement

cin>>variable;
if (condition base on the input variable)

{
//codes that are to be executed if the condition is met

statement 1;
statement 2;
statement 3;
statement 4;
}

Last edited on Dec 12, 2010 at 12:59am
Topic archived. No new replies allowed.