Example 3 nested if,else statement:
statement:
logic:
we simply use nested if,else statement because we have multiple choices. first of all we have to understand the grading system every institute have own grading system i made this program according to my institute. here first if condition will be true if the marks between 100 and 84.5 then output will be A+. if the first condition is false then compiler will check the second condition if this condition is true then then compiler will run its block of code and leave all condition similarly it will be done for all conditions. else block will be run if all if condition will be false.
program:
#include "stdafx.h"
#include "iostream"
#include"conio.h"
using namespace std;
void main()
{
int marks;
cout<<"enter the marks==";
cin>>marks;
if(marks>=84.5 && marks<100 )
{cout<<"your grade is A+";}
else
if (marks>=79.5 && marks<84.5)
{
cout<<"your grade is A";
}
else
if (marks>=74.5 && marks<79.5)
{
cout<<"your grade is B+";
}
else
if (marks>=69.5 && marks<74.5)
{
cout<<"your grade is B";
}
else
if (marks>=64.5 && marks<69.5)
{
cout<<"your grade is B-";
}
else
if (marks>=59.5 && marks<64.5)
{
cout<<"your grade is c+";
}
else
if (marks>=54.5 && marks<59.5)
{
cout<<"your grade is c";
}
else
if (marks>=49.5 && marks<54.5)
{
cout<<"your grade is D";
}
else
if (marks<49.5 && marks>=0)
{
cout<<"your grade is F";
}
else
{
cout<<"wrong entry";
}
_getch();
}
DOWNLOAD .CPP FILE
0 comments:
Post a Comment