if else practice question for beginners with solution

 #include <iostream>

using namespace std;
int main(){    
//date-12/11/2021
/*int length, breadth;
cout<<"Enter the length and breadth of the rectangle. :";
cin>>length;
cin>>breadth;
if(length==breadth){  
cout<<"yes it is square" ;
}
else {
cout<<"It is not Square";
}

// Take three int input from user from user and print greatest among them .

int num1,num2,num3;
cout<<"Enter the first number :" <<endl;
cin>>num1;
cout<<"Enter the first number :"<<endl;
cin>>num2;
cout<<"Enter the first number :"<<endl;
cin>>num3;

if (num1>num2 && num3<num1){
  cout<<"First number is greater : "<<num1;
   }
   else if (num2>num1 && num3<num2){
   cout<<"Second number is greater : "<<num2;
} else {
   cout<<"Third number is greater : "<<num3;
}

 int bholu, irfan , By_this_much;
 cout<<"Enter the age of Bholu : ";
 cin>>bholu;
 cout<<"Enter the age of Irfan : ";
 cin>>irfan;
 
if (bholu>irfan){
   cout<<"Bholu is greater than irfan "<<"By: "<<bholu-irfan;
} else{
   cout<<"Irfan is greater than bholu "<<"By: "<<irfan-bholu;
}

// Write a program to take a input a dividend and divisor and calculate and dislplay the qutotient and remainder.
int dividend, divisor, quotient, remainder;
cout<<"Enter the dividend : ";
cin>>dividend;
cout<<"Enter the divisor : ";
cin>>divisor;
quotient = dividend/divisor;
remainder = dividend%divisor;
cout<<"The quotient is : "<<quotient<<endl;
cout<<"The remainder is : "<<remainder<<endl;

// Write a c++ program to input the base and height of a triangle and calculate and display the area of triangle as 1/2bh;
int base, height, area;
cout<<"Enter the base : ";
cin>>base;
cout<<"Enter the height : ";
cin>>height;
area = (base*height)/2;
cout<<"The area of triangle is : "<<area;

// Write a program to accept a number and display wheater it is divisible by 2 and 3 or not.

int number,divisibility ;
cout<<"Enter the number to check : ";
cin>>number;
divisibility = number%6;
if(divisibility==0){
   cout<<"Yes! "<<number<<" is divisble by 2 and 3 ";
} else {
   cout<<"No! "<<number<<" is not divisble by 2 and 3 ";
}
//Write a program to accept two numbers and display the smallest number .

int num1,num2;
cout<<"Enter the first number : ";
cin>>num1;
cout<<"Enter the second number : ";
cin>>num2;
if (num2>num1 ){
   cout<<"First number is smallest : "<<num1;
} else {
   cout<<"Second number is smallest : "<<num2;
}

string answer, yes;
cout<<"Will you do hardwork ? ";
cin>>answer;
if(answer=="yes"){
   cout<<"You will get success. ";
} else{
 cout<<"You will not get succes. ";
}  */

// Program to build a simple calculator using switch Statement

   char opera ;
   float operands1, operands2;
   cout<<"Enter your first operands : "<<endl;
   cin>>operands1;
   cout<<"Enter your second operands : "<<endl;
   cin>>operands2;
    cout<<"Enter your operator (+,-,*,/ ) : ";
    cin>>opera;
   switch (opera)
   {
   case '+':
      cout<<operands1 <<" + "<<operands2 <<" = " <<operands1+operands2;
      break;
      case '-':
      cout<<operands1 <<" - "<<operands2<<" = " <<operands1-operands2;
      break;
      case '*':
      cout<<operands1 <<" * "<<operands2<<" = " <<operands1*operands2;
      break;
      case '/':
      cout<<operands1 <<" / "<<operands2<<" = " <<operands1/operands2;
      break;
   
   default: cout<<"Your did something wrong please try again! ";
      break;
   }


 



return 0;  

}

Comments

Popular posts from this blog

swapping the alternate values in given array's element ! 17/11/2022

Learning stage | c++ programs

c++ basic question