if statement

a IF statement consists of the word "if" then an expression (ex. (a <2)) then an open bracket ({), code, then a closing bracket (}). Like this:

 

if (b < 5)

{ std:cout << "b is less than 5"}

 

Now if b is > 5,  "b is less than 5" is not displayed. it is skipped over and the code keeps going. But usually if b is > 5, you still want it to do something. In that case, you would do this:

 

 

if (b < 5)

{ std:cout << "b is less than 5"}

else

{ std:cout << "b is greater than 5"}

 

So now if b is greater than five, it will display "b is greater than 5". What this code says is that if b is less than 5, display "b is less than 5". Anything else, display "b is greater than 5".

 

once again, see attachments for the attached code.

 

Check back for more tutorials!

AttachmentSize
File2.zip267 bytes