0% found this document useful (0 votes)
122 views

6-Nested If-Else and If-Else-If Statements

This document discusses nested if-else statements in C++. It provides examples to find the minimum and maximum of three numbers, subtract the larger of two numbers from the smaller, and determine if a character is a vowel, consonant, capital letter, or small letter using nested if/else statements. The objectives are to understand nested if-else concepts and how to implement them in C++. Sample code is given to grade marks in ranges from A to F using if/else statements.

Uploaded by

Nemisis Pubg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
122 views

6-Nested If-Else and If-Else-If Statements

This document discusses nested if-else statements in C++. It provides examples to find the minimum and maximum of three numbers, subtract the larger of two numbers from the smaller, and determine if a character is a vowel, consonant, capital letter, or small letter using nested if/else statements. The objectives are to understand nested if-else concepts and how to implement them in C++. Sample code is given to grade marks in ranges from A to F using if/else statements.

Uploaded by

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

Programming Fundamentals

Topic: Nested If Else

Course Instructor: Maria

Session: Spring 2019

Department of Computer Science & Information Technology


The University of Lahore, Lahore, Pakistan
Objectives
The objective of the lab is to understand the concept and how to implement IF-Else statements and nested
IF-Else in C++. At the end of this lab students will be able to use all type of if-else statements.

Sample Program.
Write a program which takes marks as input and then shows output as follows:

Grade Marks
A 100-85
B 84-69
C 68-53
D 54-40
F Below 40

Sample Code:

#include<iostream>
using namespace std;
int main()
{
char grade;
cout<<"Enter grade\t";
cin>>grade ;

if (grade=='A' || grade=='a')
cout<<"Your marks lie between 100-85\n";
else if (grade=='B' || grade=='b')
cout<<"Your marks lie between 84-69\n";
else if (grade=='C' || grade=='c')
cout<<"Your marks lie between 68-53\n";
else if (grade=='D' || grade=='d')
cout<<"Your marks lie between 54-40\n";
else if (grade=='F' || grade=='f')
cout<<"Your marks are Below 40\n";
else
cout<<"Invalid Grade Entered\n";
return 0;
}
Tasks
Task 1:

Write a program which takes 3 numbers as input then it finds the minimum and maximum number and
print output as follows:
Enter num 1: 3
Enter num 2: 6
Enter num 3: 1

6 is maximum
1 is minimum

Enter num 1: 3
Enter num 2: 3
Enter num 3: 3

All numbers are equal

Task 2:

Write a program in which it takes two numbers from keyboard as input and subtract larger
number from smaller?
Enter num 1: 3
Enter num 2: 6

Subtraction : 6 – 3 = 3

Task 3:

Write a Program using Nested if-else structure. The program will get a Single Character from
user and Tell either it is Vowel or consonant and it a capital or small letter or not an alphabet?

Sample output:

Enter a character : A
A is a Vowel and it is Capital Letter.

Enter a character: y
y is a consonant and it is small Letter.

Enter a character: 1
It is not an alphabet.

You might also like