Pages

Friday, April 4, 2014

Switch statement example in c to calculate grade points gpa

A simple c++ program  which shows using of  switch statement in c++

C++ Program which takes input a grade and display Grade Points Average GPA


Program takes inputs A,a, B,b, C,c,D,d,F,f other option will be consider as invalid input


Program code:



#include<iostream>
using namespace std;
int main()
{
char grade; double gpa=0.0;
cout<<"Enter your Grade=  ";
cin>>grade;
switch(grade)
{
  caseA:
  casea:
  gpa=4.0;
  cout<<"your GPA is "<<gpa;
  break;
      
    caseB:
    caseb:
    gpa=3.0;
    cout<<"your GPA is "<<gpa;
    break;
      
     caseC:
     casec:
     gpa=2.0;
     cout<<"your GPA is "<<gpa;
     break;

      caseD:
      cased:
      gpa=1.0;
      cout<<"your GPA is "<<gpa;
      break;
        
       caseF:
       casef:
       gpa=0.0;
       cout<<"your GPA is "<<gpa;
       break;
    
    default:
    cout<<"invalid grade entered";
    break;
  }
return 0;
}



Copy the code and run on compiler change the code examine output and dry run it for better understandings.
Sample input

switch statement example c++ calculate grade point gpa
switch statement example c++ calculate grade point

Find  more Examples Here. C++ Simple Examples


Related Posts by Categories

0 comments:

Post a Comment