0
where to use the if statements??
actually i didn't get where to use the if statements
2 Answers
+ 2
Use "if statement" when you have some decision to make on the basis of conditions.
Example: 4 is even or odd??
if(4%2==0)
cout<<"even";
else
cout<<"not even";
0
if statements are used if you want a line of code to be ran under specific conditions. For example if you were on a website, and you wanted to print something else if the user was 18 or older you would write
if (age >= 18){
cout << "You are allowed to enter" << endl;
else{
cout << "You are not old enough" << endl;
So it only runs if that condition is true, otherwise it runs the default code else statement. Which would be anything under 18