6-Nested If-Else and If-Else-If Statements
6-Nested If-Else and If-Else-If 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
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.