top of page
Conditional if else clause 

In this lesson, we will explain how to make an if and else conditional statement. Conditional statements simply set a condition. If the condition is met, the code will be executed. If the condition is not met, the code will not be executed.

An example of a conditional sentence is: If the password is entered correctly, print (The password is correct) and if the password is incorrect, print (The number you entered is incorrect), and the method of writing the code is as follows:

Project: What is a password?

#include<iostream>//We start by placing the libraries
using namespace std;//We start by placing the libraries
int main(){//main function
int password=123;//We define a variable for the password
int enter;//We declare a variable for user writing
cout<<"enter the password please";//We perform a command to print the password entry
cin>>enter;//We have the user enter the password
if (enter == 123){
//if It was the secret number
What you enteredIt equals 123 Som fulfilling the condition 
// We put inside the bracket the condition that we want to achieve And we openA bow We then put what will happen when the condition is metWe close it
cout<<"The password you entered is right";}
//We perform the print command if the number we entered is 123 
else { cout<<"The password you entered is wrong bro";}
//Other than that If the condition is not met, print that the password you entered is incorrect
return 0;
}

image.png
image.png
bottom of page