Pages

January 29, 2013

Decision Making- Nested If else in C++ (OOPs)

if else ladder (Nested if else) statements in C++ (OOPs) programming language banner


This statement can be used to select any one statement or a block which contains a set of instructions. Only that statement will execute which is true according to the data entered and rest other conditions will not executed.

FORMAT:
if(expression1)
Statement1;
else if(expression2)
statement2;
else if(expression3)
statement3;

/* Program to enter student details and allow the grade to the students according to his scores*/

#include<iostream.h>
#include<conio.h>
main()
{
      int roll,s1,s2,s3,s4,s5;
      float per;
      char name[10];
      cout<<"\n Enter student's name and roll number";
      cin>>name>>roll;
      cout<<"\n Enter marks in Physics, Chemistry, Maths, English, Physical";
      cin>>s1>>s2>>s3>>s4>>s5;
      per=(s1+s2+s3+s4+s5)/5.0;
      if(per>=90.0)
      {
                   cout<<"\n R.No.\tName\tPercentage";
                   cout<<"\n "<<roll<<"\t"<<name<<"\t"<<per;
                   cout<<"\n A+: Brilliant Performace";
                   }
      else if(per>=80.0 && per<90.0)
      {
           cout<<"\n R.No.\tName\tPercentage";
           cout<<"\n "<<roll<<"\t"<<name<<"\t"<<per;
           cout<<"\n A: Good Performance";
           }
      else if(per>=70.0 && per<80.0)
      {
           cout<<"\n R.No.\tName\tPercentage";
           cout<<"\n "<<roll<<"\t"<<name<<"\t"<<per;
           cout<<"\n B+: Average Performance";
           }
      else if(per>=60.0 && per<70.0)
      {
           cout<<"\n R.No.\tName\tPercentage";
           cout<<"\n "<<roll<<"\t"<<name<<"\t"<<per;
           cout<<"\n B: OK Performance";
           }
      else if(per<60.0)
      {
           cout<<"\n R.No.\tName\tPercentage";
           cout<<"\n "<<roll<<"\t"<<name<<"\t"<<per;
           cout<<"\n C+: Just Pass";
           }
      else
      {
          cout<<"\n R.No.\tName\tPercentage";
          cout<<"\n "<<roll<<"\t"<<name<<"\t"<<per;
          cout<<"\n C: FAIL";
          }
      getch();
      }
output of program to student details and performance of A+ grade using if else ladder in C++ (OOPs)
output of program to student details and performance of A grade using if else ladder in C++ (OOPs)
      

No comments:

Post a Comment