Contenido del Curso
Introduction to C++
Introduction to C++
Else Expression
In the previous task, we mentioned what the program should do if our statement is true, but what to do if we need to specify actions if the condition is also false. For such situations in C++ exists the else
statement.
The syntax is the following:
Let’s define if the number is even (can be divided by 2 into two equal numbers) or not, using the else
statement:
The code accepts a number from the user. If the number by division by 2 gives 0 as the remainder (for example 6/2 = 3 the remainder is 0) then the condition is true and the user printed an even number, otherwise, the number is not even.
¡Gracias por tus comentarios!