Hey guys, what is up. In this particular post, we will be talking about questions on a conditional statement.

Updated on (27/9/2021)

## Ques1: To make a menu-driven calculator using a conditional statement.

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int n;

float a,b,c;

cout<<“CALCULATOR \n 1.) ADDITION \n 2.) SUBTRACTION \n 3.) MULTIPLICATION \n 4.) DIVISION”;

cout<<“\nENTER A = “;

cin>>a;

cout<<“ENTER B = “;

cin>>b;

cout<<“\nENTER YOUR CHOICE BETWEEN 1-4 = “;

cin>>n;

if(n<1 && n>4)

{

cout<<“INVALID CHOICE”;

}

else if(n==1)

{

c=a+b;

}

else if(n==2)

{

c=a-b;

cout<<“SUBTRACTION = “<<c;

}

else if(n==3)

{

c=a*b;

cout<<“MULTIPLICATION = “<<c;

}

else

{

c=a/b;

cout<<“DIVISION = “<<c;

}

getch();

}

OUTPUT:

## Ques2: To print the grade of a student taking all the values from the user using a conditional statement.

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

float english, maths, science, social, hindi, total, percentage;

cout<<“ENTER VALUES OF ALL THE SUBJECTS: “;

cout<<“\nENGLISH= “;

cin>>english;

cout<<“MATHS= “;

cin>>maths;

cout<<“SCIENCE= “;

cin>>science;

cout<<“SOCIAL= “;

cin>>social;

cout<<“HINDI= “;

cin>>hindi;

total=english + hindi + maths + social + science;

percentage= (total/500) * 100;

if (percentage>90 && percentage<=100)

{

}

else if (percentage>80 && percentage<=90)

{

}

else if (percentage>70 && percentage<=80)

{

}

else if (percentage>60 && percentage<=70)

{

}

else if (percentage>50 && percentage<=60)

{

}

else

{

cout<<“\nFAIL”;

}

getch();

}

## Ques3: To calculate the area and perimeter of circle, square, and rectangle using conditional statement.

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

float area,perimeter;

cout<<” AREA \n 1.) SQUARE \n 2.) RECTANGLE \n 3.) CIRCLE \n PERIMETER \n 4.) SQUARE \n 5.) RECTANGLE \n 6.) CIRCLE “;

cout<<“\nENTER OPTION FROM 1 TO 6 WHICH YOU WANT TO PERFORM: “;

cin>>option;

if(option<1 && option>6)

{

cout<<“\n INVALID OPTION”;

}

else if(option==1)

{

cout<<“\n ENTER SIDE OF SQUARE= “;

cin>>side;

area= side*side;

cout<<“\n AREA OF SQUARE= “<<area;

}

else if(option==2)

{

cout<<“\n ENTER LENGTH AND BREADTH OF RECTANGLE= “;

cout<<“\n LENGTH= “;

cin>>length;

cout<<“\n AREA OF RECTANGLE= “<<area;

}

else if(option==3)

{

cout<<“\n ENTER RADIUS OF CIRCLE= “;

cout<<“\n AREA OF CIRCLE= “<<area;

}

else if(option==4)

{

cout<<“\n ENTER SIDE OF SQUARE= “;

cin>>side;

perimeter= 4*side;

cout<<“\n PERIMETER OF SQUARE= “<<perimeter;

}

else if(option==5)

{

cout<<“\n ENTER LENGTH AND BREADTH OF RECTANGLE= “;

cout<<“\n LENGTH= “;

cin>>length;

cout<<“\n PERIMETER OF RECTANGLE= “<<perimeter;

}

else if(option==6)

{

cout<<“\n ENTER RADIUS OF CIRCLE= “;

cout<<“\n PERIMETER OF CIRCLE= “<<perimeter;

}

getch();

}

## QUES4: To calculate the tax a person has to pay based on his salary.

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

float sal, tax;

cout<<“ENTER SALARY = “;

cin>>sal;

if(sal<=10000)

{

cout<<“NO TAX”;

}

else if(sal>10000 && sal<=20000)

{

tax = (0.10*sal);

cout<<“TAX = “<<tax;

}

else if(sal>20000 && sal<= 30000)

{

tax = (0.20*sal);

cout<<“TAX = “<<tax;

}

else

{

tax = (0.25*sal);

cout<<“TAX = “<<tax;

}

getch();

}

In the upcoming post, you will be getting information related to technology and switch statement in C++. If you haven’t read about what is if else in c++ then go and read this. Also, stay tuned for the upcoming post

Categories: CODING

### 1 Comment Open an account