0% found this document useful (0 votes)
9 views12 pages

Lecture 2 Week 4

The document covers the basics of conditional statements in programming, specifically focusing on 'if' and 'if-else' statements in C++. It includes examples of code demonstrating how to use these statements to evaluate conditions and produce output based on the results. Additionally, it provides practice questions and tasks for further understanding of the concepts discussed.

Uploaded by

Umer Blouxh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views12 pages

Lecture 2 Week 4

The document covers the basics of conditional statements in programming, specifically focusing on 'if' and 'if-else' statements in C++. It includes examples of code demonstrating how to use these statements to evaluate conditions and produce output based on the results. Additionally, it provides practice questions and tasks for further understanding of the concepts discussed.

Uploaded by

Umer Blouxh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 12

PROGRAMMING

FUNDAMENTAL
LAB
Umer Ahmad
Lecture 2 week 4
If
Condition
al
statement
s If- else
IF
STATEMEN
T
FLOWCHA
RT
• If the condition or Boolean expression
evaluates to true, then the code block inside
the if statement will be executed.
If statement
• If condition is false then compiler skip the if
body.
• #include<iostream>
• #include<conio.h>
• using namespace std;
• int main() {
• int marks;
• cout<< "Enter your marks you get in the exams"<<
endl;
Example
• cin>> marks;
program
• if (marks>=40) {
• cout<< "Congratulation, you have passed the exam.
";
• }
• getch();
• return 0;
• }
• #include <iostream>
• using namespace std;
• int main () {
• // local variable declaration:
• int a = 10;
• // check the boolean condition
If statement • if( a < 20 ) {
program • // if condition is true then print the following
• cout << "a is less than 20;" << endl;
• }
• cout << "value of a is : " << a << endl;
• return 0;
• }
Practice question
• Write a C++ program to accept two integers and check whether they are
equal or not.
• Data to be test : 8 8
desired Output :
Number1 and Number2 are equal
IF ELSE
FLOWCHA
RT
• If statement with an optional else statement.
In which, if statement is executed only when
If-else •
the condition is true.
statement • And else statement is executed only when
the condition is false.
• #include <iostream>

• using namespace std;

• int main () {

• // local variable declaration:

• int a = 100;

• // check the boolean condition

• if( a < 20 ) {

• // if condition is true then print the following


If else program • cout << "a is less than 20;" << endl;

• } else {

• // if condition is false then print the following

• cout << "a is not less than 20;" << endl;

• }

• cout << "value of a is : " << a << endl;

• return 0;

• }
PRACTICE
PROGRAM
Check Whether Number is Even or Odd using if else.
Hint: n % 2 == 0
LAB TASK
Check Vowel or a Consonant Manually

You might also like