# Conditional Structure Programming Exercise P-6

#### What is IF-Statement in C and C++ Programming?

IF Statement Programming Exercise P-1 in c And C++

IF Statement Programming Exercise P-2

IF Statement Programming Exercise P-3

Conditional Structure Programming Exercise P-4

IF Statement Programming Exercise Part-5

#### Less than 25 Cool day

```#include<iostream.h>
#include<conio.h>
main()
{
int temp;
clrscr();
cout<<"Enter temperature ? ";
cin>>temp;
if(temp >35)
cout<<"Hot day";
else if(temp >= 25)
cout<<"Pleasant day";
else
cout<<"Cool day";
getch();

}```

#### The program should input the type of vehicle and display the charges for toll plaza according to the following rates:Car = Rs. 30Bus = Rs. 80Truck = Rs. 100

```#include<iostream.h>
#include<conio.h>
main()
{
char op;
clrscr();
cout<<"C- Car"<<endl;
cout<<"B- Bus"<<endl;
cout<<"T- Truck"<<endl;
cout<<"Enter Your Option[C or B or T]?"<<endl;
cin>>op;
if(op == 'C')
cout<<"Toll Plaza Charges = 30 ";
else if(op == 'B')
cout<<"Toll Plaza Charges = 80 ";
else if(op == 'T')
cout<<"Toll Plaza Charges = 100 ";
getch();
}```

#### Q.18 Write a program that converts ASCII number to character or character to ASCII number. The program should display the menu for conversion options. Interaction with the program should be as follows:1- Convert ASCII to Character2- Convert Character to ASCIIEnter your option ? 1Enter a number ? 65The corresponding character is : A

```#include<iostream.h>
#include<conio.h>
main()
{
int n, op;
char ch;
clrscr();
cout<<"1- Convert ASCII to Character"<<endl;
cout<<"2- Convert Character to ASCII"<<endl;
cin>>op;
if(op == 1)
{
cout<<"Enter ASCII number ? ";
cin>>n;
ch = n;
cout<<"Corresponding character of " <<n<< " is :"<<ch;
}
else if(op == 2)
{
cout<<"Enter a character ? ";
cin>>ch;
n = ch;
cout<<"ASCII value of "<<ch<<" is : "<<n;
}
getch();
}```

#### Q.19 Write a program that inputs any number of month of the year and displays the name and number of days of the entered month. For example, if 4 is entered for the number of month of the year, program should display “April has 30 days”.

```#include<iostream.h>
#include<conio.h>
main()
{
int no_month;
clrscr();
cout<<"Enter number of month of the year [1-12]?"<<endl;
cin>>no_month;
if(no_month == 1)
cout<<"January has 31 days ";
else if(no_month == 2)
cout<<"February has 28 days ";
else if(no_month == 3)
cout<<"March has 31 days ";
else if(no_month == 4)
cout<<"April has 30 days ";
else if(no_month == 5)
cout<<"May has 31 days ";
else if(no_month == 6)
cout<<"June has 30 days ";
else if(no_month == 7)
cout<<"July has 31 days ";
else if(no_month == 8)
cout<<"August has 31 days ";
else if(no_month == 9)
cout<<"September has 30 days ";
else if(no_month == 10)
cout<<"October has 31 days ";
else if(no_month == 11)
cout<<"November has 30 days ";
else if(no_month == 1)
cout<<"December has 31 days ";
getch();
}```

#### Q.20 Write a program that calculates income tax for three categories of income groups. The tax is computed as follows:i. If the income is less than Rs. 25,000, the tax is 5% of the income.ii. If the income is equal to Rs. 25,000, the tax is Rs. 1250.iii. If the income is greater than Rs. 25,000, the tax is Rs. 1250 plus 15% of the income exceeding Rs. 25,000.

```#include<iostream.h>
#include<conio.h>
main()
{
int income;
double tax;
clrscr();
cout<<"Enter income ? "<<endl;
cin>>income;
if(income < 25000)
tax = income * 5.0/100.0;
else if(income == 25000)
tax = 1250;
else if(income > 25000)
tax = 1250 + (income-25000)*15.0/100.0;
cout<<"Income Tax = "<<tax;
getch();
}```

#### Q.21 Write a program that calculates the commission of a salesman of a departmental store according to the following:i. If sale is less than Rs. 50, there is no commission.ii. If sale is greater than or equal to Rs. 50 and less than or equal to Rs.500, the commission is 10% of the sale.iii. If sale is greater than Rs.500, the commission is Rs 50+15% of the sale above Rs. 500

```#include<iostream.h>
#include<conio.h>
main()
{
int sale;
double commission;
clrscr();
cout<<"Enter sale ? ";
cin>>sale;
if(sale < 50)
commission = 0;
else if(sale >=50 && sale <=500)
commission = sale*10.0/100.0;
else if(sale > 500)
commission = 50 + (sale-500)*15.0/100.0;
cout<<"commission of a salesman = "<<commission;
getch();
}```

#### Q.22 Write a program that inputs marks obtained by a student in a subject. The total marks are 100. The program finds out grade of the student using the if-else nested structure. The grade is found out as follows:If marks are equal to or greater than 90, grade is “A+”.If marks are equal to or greater than 70, and less than 90, grade is “A”.If marks are equal to or greater than 50, and less than 70, grade is “B”.If marks are less than 50, grade is “F”.

```#include<iostream.h>
#include<conio.h>
main()
{
int marks;
clrscr();
cout<<"Enter marks of a student ? ";
cin>>marks;
if(marks >=90)
else if(marks >=70 && marks < 90)
else if(marks >=50 && marks < 70)
else if(marks < 50)
getch();
}```

#### Q.23 Write a program that inputs the radius of a circle. It calculates area of circle if user enters 1 as choice. It calculates circumference of the circle if the user enters 2 as choice.

```#include<iostream.h>
#include<conio.h>
main()
{
int op;
clrscr();
cout<<"Enter radius of circle ? ";

cout<<"1-Area of circle "<<endl;
cout<<"2-Circumference of circle "<<endl;
cin>>op;
switch(op)
{

case 1:
cout<<"Area of circle :"<<area;
break;
case 2:
cout<<"Circumference of circle :"<<circum;
break;
}
getch();
}```

#### Q.24 Write a program that inputs an integer number and displays the corresponding name of the month using switch statement. For example, if a user enters an integer value 3 then “March” should be displayed and so on. If value is not between 1 and 12 then program should display a message “Invalid Month”.

```#include<iostream.h>
#include<conio.h>
main()
{
int n;
clrscr();
cout<<"Enter number of month ? ";
cin>>n;
switch(n)
{

case 1:
cout<<"January";
break;
case 2:
cout<<"February";
break;
case 3:
cout<<"March";
break;
case 4:
cout<<"April";
break;
case 5:
cout<<"May";
break;
case 6:
cout<<"June";
break;
case 7:
cout<<"July";
break;
case 8:
cout<<"August";
break;
case 9:
cout<<"September";
break;
case 10:
cout<<"October";
break;
case 11:
cout<<"November";
break;
case 12:
cout<<"December";
break;
default:
cout<<"Invalid Month";
}
getch();
}

```

#### Q.25 Write a program that gets an integer value and tests whether the given number is odd or even using switch statement.

```#include<iostream.h>
#include<conio.h>
main()
{
int n;
clrscr();
cout<<"Enter any number ? ";
cin>>n;
switch(n%2)
{

case 0:
cout<<n<<" is even number";
break;
case 1:
cout<<n<<" is odd number";
break;
}
getch();
}

```

#### Q.26 Write a program that inputs a single digit (0 to 9) from the keyboard and displays the input value in words. For example, if the input is 9, then print Nine. Use the switch statement.

```#include<iostream.h>
#include<conio.h>
main()
{
int n;
clrscr();
cout<<"Enter any digit between 0 to 9 ? ";
cin>>n;
switch(n)
{

case 1:
cout<<"One";
break;
case 2:
cout<<"Two";
break;
case 3:
cout<<"Three";
break;
case 4:
cout<<"Four";
break;
case 5:
cout<<"Five";
break;
case 6:
cout<<"Six";
break;
case 7:
cout<<"Seven";
break;
case 8:
cout<<"Eight";
break;
case 9:
cout<<"Nine";
break;

default:
cout<<"Invalid input";
}
getch();
}```