#Mastery15

1017 15

Hello i am doing my 15 al over again because i want to get my two points!

I will be teaching you how to use a conditional if.

First of all lets see why conditionals are useful.

For me personally, the use of conditionals is  one of the most important things in c++ programming or in any kind of language or algorithm. Because is such an easy way  to do things, or to lead the user where he wants to go.

An if or conditional, is to give the user an option if he wants something or no, or also if the user put something he can´t the program will say no, because you said tha IF he put that it will say no.

But, lets do an example for you to understand it better.

the syntax for using an if is very easy:

“if (conditional)

{

}”

Yes, is that simple.

But let say you ask the user for a number between 1 and  10 and the name of the variable that the user will give us is “num”.

if (num 10) //This is the condition

{

     cout

}

So what did i did here. In words this tell “If the number the user gives is less than 1 or more than 10, then print (Your number is invalid).

As you can se is very simple and you cant put various times or combine it with for loops, while loops or whatever you want.

Hope you learn from this!

CC BY 4.0 #Mastery15 by Juan Carlos is licensed under a Creative Commons Attribution 4.0 International License.

Comments are closed.