If else problems with solution

  // date --> 09-10-2021 

  // if esle exercise
            
// // difference between signed and unsigned int ;
// unsigned int num = -1;
// int x = num;
// cout<<num<<", "<<x;

/*//Q- Take valuse of length and breadth 
 of a rectangle from user and check if it is square or not .

int length, breadth ;
cout<<"Enter the lenght of the rectangle : "<<endl;
cin>>length;
cout<<"Enter the breadth of the rectangle : "<<endl;
cin>>breadth;

if (length==breadth){
  cout<<"It is a square"<<endl;
}else{
  cout<<"It is not a square";

//Q- Take two values from user and print the gratest among them;

int a, b;
cout<<"Enter the a number : "<<endl;
cin>>a;
cout<<"Enter the b number: "<<endl;
cin>>b;

if (a>b){
  cout<<"A is greater than b : " <<a<<">"<<b;
}else{
  cout<<"b is grater than a : " <<b<<">"<<a;

//Q- A shop will give discount of 10%, if cost of purchased quantity is more than 1000.
// Ask user for quantity suppose one unit will cost 100 . Judge and print total cost for user.

 int quantity, Price,Discount, Amount; 
cout<<"Enter the quantity of your purchased product : ";
cin>>quantity;
Price = quantity*100;

if (quantity>10){
Price = quantity*100;
Discount = (10*Price)/100;
Amount = Price - Discount ;
cout<<"Price : " <<Price<<endl;
cout<<"10% Discount : " <<Discount<<endl;
cout<<"Amount : " <<Amount; }
else{
  cout<<"Make sure to purchase of more than Rs 1000. You have only purchase "<<Price;

//Q- A company decided to give bonus of 5% to employee if his/her year of service is 
// more than 5 years . Ask user for their salary and year of service and print the net bonus amount. 
int salary, year_of_service, bonus, net_amount;
cout<<"Enter your salary : ";
cin>>salary;
cout<<"Enter your Year of service : ";
cin>>year_of_service;

if (year_of_service>5){
  bonus = (salary*5)/100;
  cout<<"The bonus is : "<<bonus<<endl;
  net_amount = salary+bonus;
  cout<<"The net amount is : "<<net_amount;
} else{
  cout<<"No bonus because you have not completed the 5 year of service " ;
} */

/*
A scholl has following rules for grading system:
a. Below 25 - F
b. 25 to 45 - E
c. 45 to 50 - D
d. 50 to 60 - C
e. 60 to 80 - B
f. Above 80 - A
Ask user to enter marks and print the corresponding grade.

int marks ;
cout<<"Enter your marks : ";
cin>>marks;
if ( marks<=25){
  cout<<"Your grade is F ";
}  else if (marks>25 && marks<=45){
cout<<"Your grade is E ";
} else if (marks>45 && marks<=50){
  cout<<"Your grade is D ";
} else if (marks>50 && marks <= 60){
  cout<<"Your grade is C ";
} else if (marks>60 && marks<=80){
  cout<<"Your grade is B ";
} else{
  cout<<"Your grade is A ";


//Q- Take input of age of 3 people by user and determine oldest and youngest among them.

int a , b, c;
cout<<"Enter the age of first person : " <<endl;
cin>> a ;
cout<<"Enter the age of second person : " <<endl;
cin>> b ;
cout<<"Enter the age of third person : " <<endl;
cin>> c ;

if(a>b && a>c){
  cout<<"a is the oldest person "<<endl;
} else if (b>a && b>c){
  cout<<"b is oldest person "<<endl;
} else {
  cout<<"c is oldest person"<<endl;
}
if (a<b && a<c){
  cout<<"a is the youngest person ";
} else if (b<a && b<c){
  cout<<"b is the youngest person ";
}else {
  cout<<"c is the youngest person ";
}  

// Q- Write a program to print absolute value of a number enterd by user 
e.g- inputt:1
input:2

int num1, num2;
cout<<"Enter your 1st number : "<<endl;
cin>>num1;
cout<<"Enter your 2nd number : "<<endl;
cin>>num2;
cout<<"The absolute value of 1st number is : "<<abs(num1)<<endl;
cout<<"The absolute value of 2nd number is : "<<abs(num2);

   --------------->OR<--------------------
   
   int x,y ;
   cout<<"Enter your number : "<< endl;
   cin>>x;
   if(x<0){
     x=x*(-1);
   }
   cout<<"Absolute value is : "<<x<<" units"; */
   
  /*Q- A students will not be allowed to sit in exam if his/her attendence is less than 75%. 
   Take the following input from user:
  Number of classes held
  Number of classes attended .
  And print percentage of class ateended .
  Is studend is allowed to sit in exam or not .

  int class_held, attendence, percentage , class_attended, percentage_of_class_attended; 
 
 cout<<"Please enter the number of class that you attended : "<<endl;
 cin>>class_attended;
 cout<<"Please enter the number of class that is held  : "<<endl;
 cin>>class_held;
 percentage_of_class_attended = (class_attended*100)/class_held;
 cout<<"The percentage of class attend is : "<<percentage_of_class_attended<<"%" <<endl;
 if (percentage_of_class_attended>70){
   cout<<"You can sit in examination "<<endl;
 } else {
   cout<<"You can't sit in examination because your attence percented is less than 70%."<<endl;
 } */
 
 /*
 if 
 x=2
 y = 5
 z=0
 then find values of the following expressions:
 a. x==2
 b. x!=5;
 c. x!=5 && y >=5
 d.z !=0 || x== 2
 e.!(y<10)
 
int x,y,z , checking1, checking2 , checking3, checking4, checking5 ;
x=2;
y=5;
z=0;
checking1 = (x==2);
cout<<checking1<<endl; 

checking2 = (x!=5);
cout<<checking2<<endl; 

checking3 = (x!=5 && y >=5);
cout<<checking3<<endl; 

checking4 = !(y<10);
cout<<checking4<<endl; 

checking5 =(z !=0 || x== 2);
cout<<checking5<<endl;  */



/* Write a program to check wheater a entered character is lowecase (a to z) or uppercase (A to Z). 

char x;
cout<<"Enter your character : "<<endl;
cin>>x;
if(isupper(x)){
  cout<<"The character you entred is uppercase ";
} else{
  cout<<"The character you entred is lowercase ";
}  */

/*
Write a program to check if a year is leap year or not. If a year is divisible by 4 then it
is leap year but if the year is century year like 2000 , 1900 , 2100 then it must be divisible by 400.

 int year, leap_year, century_year; 
cout<<"Enter your year to check : "<<endl;
cin>>year;
leap_year =year%4;
century_year = year%400;

if (leap_year==0 && century_year ==0){
  cout<<"This is year is leap year as well as century year .";
} else if (leap_year==0)
{
  cout<<"This year is only leap year not century year. ";
} else{
  cout<<"This year is neither leap year nor century year . ";
} */

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