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

Programming Fundamentals Lab 05 (Nested If-Else and If-Else-If Statements)

This document provides a lab manual for programming fundamentals lab 5 on nested if-else and if-else-if statements in C++. It includes objectives, a sample program to determine a grade based on marks using if-else-if statements, an explanation of using logical AND operator, and 4 tasks for students to write programs using nested if/else statements. The tasks include programs to print messages based on a person's age, find the minimum and maximum of 3 numbers, subtract the larger of two numbers from the smaller, and determine if a character is a vowel or consonant and lowercase or uppercase.

Uploaded by

Ahmad Abduhu
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)
358 views

Programming Fundamentals Lab 05 (Nested If-Else and If-Else-If Statements)

This document provides a lab manual for programming fundamentals lab 5 on nested if-else and if-else-if statements in C++. It includes objectives, a sample program to determine a grade based on marks using if-else-if statements, an explanation of using logical AND operator, and 4 tasks for students to write programs using nested if/else statements. The tasks include programs to print messages based on a person's age, find the minimum and maximum of 3 numbers, subtract the larger of two numbers from the smaller, and determine if a character is a vowel or consonant and lowercase or uppercase.

Uploaded by

Ahmad Abduhu
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

Lab Manual (Lab 5)

Topic: Nested if–else and if–else-if Statements

Lab Instructor: Ahmad Abduhu

Session: Fall 2018

School of Systems and Technology


UMT 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:
Marks Output
87 – 100 Grade A
80 - 87 Grade B+
72 – 80 Grade B
67 – 72 Grade C+
60 - 67 Grade C
Below 60 Failed
Sample Code:

#include <stdio.h>
int main()
{
int marks;
printf ( “Enter an marks\n”);
scanf ( “%d”, &marks );

if (marks >= 87 && marks <=100 )


printf("Grade A\n");
else if (marks >= 80 && marks < 87)
printf("Grade B+\n");
else if (marks >= 72 && marks< 80)
printf("Grade B\n");
else if (marks >= 67 && marks < 72)
printf("Grade C+\n");
else if (marks >= 60 && marks< 67)
printf("Grade C\n");
else
printf("Failed\n");
return 0;
}
In above example logical operator && is used and because of this && operator condition will
only be satisfied if both the conditions in a single if are true. If any of the condition is false
because of && operator the whole condition will be treated as false.
Lab Tasks
Task 1:

Write a program, which takes age as input from user and prints appropriate message depending upon the
following conditions:
 
 If age less than 6 then prints, “What a nice child!”
 If age is between 6 and 9 then prints, “That’s a good age!”
 If age is between 9 and less than 20 then prints, “Ah! In the prime of life”
 If age between 20 and less than 30 then prints, “Watch out, the younger ones are gaining on
you.”
 More than 30 then it prints, “Well, have fun, and don’t look back.”

Task 2:

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

Task 3:

Write a program in which it takes two numbers from keyboard as input and subtract larger
number from smaller?

Task 4:

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

Sample output:

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

Enter a character: y
y is not a Vowel and it is small Letter.

You might also like