Write a program in C++ using switch statement

0

 Write a program in C++ using switch statement that contain option as under

 

Enter 1--> To Find Largest Number Among Three Variables.

Enter 2--> To Find ODD or EVEN

Enter 3--> To Find Condition of Water

Enter 4--> To Find Grade Of Student

                   

Detail of Option 3

Temperature Less than 0 = ICE

Temperature Greater than 0 &  Less than 100 = Water

Temperature Greater than 100 = STEAM

 

Detail of option 4

 

 

grade >= 90 è Grade A grade >= 80 è Grade B grade >= 70 è Grade C grade >= 60 è Grade D








Codes of Program:
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
      cout<<"___Created By Jhangir Mughal___\n**___Contact: 03131569380___**"<<endl;
      int num1;
      cout<<"Enter 1,2,3,4"<<endl;
      cin>>num1;
      switch(num1)
      case 1:
      {
      cout<<"To Find Greater Integer"<<endl;
      int a,b,c;
      cout<<"Enter 3 integers: "<<endl;
      cin>>a>>b>>c;
      if (a>b&&a>c) 
      cout<<"Greater value is: "<<a<<endl;
      else
      if(b>c&&b>a)
      cout<<"Greater Value is: "<<b<<endl;
      else
      if(c>a&&c>b)
      cout<<"Greater Value is: "<<c<<endl;
      else
      cout<<"Values are Equal."<<endl;
      break;
 
      case 2:     
      cout<<"To Check Even or Odd"<<endl;
      int i;
      cout<<"Enter an integer"<<endl;
      cin>>i;
      if(i%2==0)
      cout<<"Your entered integer is EVEN"<<endl;
      else
      cout<<"Your entered integer is ODD"<<endl;
      break;
      
      case 3:
      cout<<"To Find Ice, Water or Steam"<<endl;
      int temp;
      cout<<"Enter Temperature of Water"<<endl;
      cin>>temp;
      if(temp<0)
      cout<<"\nICE\n(Temperature is Less than 0)"<<endl;
      else
      if(temp<100 && temp>=0)
   cout<<"\nWATER\n(Temperature is Greater than 0 and Less than    100)"<<endl;
      else
      if(temp>=100)
       cout<<"\nSTEAM\n(Temperature is Greater than or equal   to 100)"<<endl;
      break;
      
      case 4:
      cout<<"To Find Grade"<<endl;
      float per;
      cout<<"Enter your Percentage:"<<endl;
      cin>>per;
      if (per>=90)
      cout<<"Your Grade is 'A'."<<endl;
      else
      if (per>=80)
      cout<<"Your Grade is 'B'."<<endl;
      else
      if (per>=70)
      cout<<"Your Grade is 'C'."<<endl;
      else
      if (per>=60)
      cout<<"Your Grade is 'D'."<<endl;
      else
      cout<<"Your Grade is Not Defined"<<endl;
      break;
      
      default:
      cout<<"You entered an invalid number"<<endl;
      }
getch();
return 0;
}

Output of Program:
Switch Statement Program in C++


Post a Comment

0Comments
Post a Comment (0)