C++ program that inputs experience and age of a person and calculate the salary.

Q51. Write a C++ program that inputs experience and age of a person. The salary of the person is 6000 if the person is experienced and his age is more than 35, otherwise if the person is experienced and his age is more 28 but less than 35 than the salary should be 4800 otherwise for experienced person the salary should be 3000 and for inexperienced person the salary be 2000.

Ans.

#include<iostream.h>   //for standard input and output

#include<conio.h>      //for clrscr()

 

//Main function

void main()

{

int exper,age,salary;

 

clrscr();  //For clear screeen

cout<<“\n The person is experienced?”;

cout<<“\n Enter 1 for yes, 0 for no: “;

cin>>exper;

cout<<“\n Enter age of the person: “;

cin>>age;

 

salary=(exper)?((age>35)?6000:(age>28)?4800:3000):2000;

 

cout<<“\n The salary of the person is: “<<salary;

 

getch();//To hold the output screen

}

//End of main()

 

 

OUTPUT1:

 

The person is experienced?

Enter 1 for yes, 0 for no: 1

Enter age of the person: 40

The salary of the person is: 6000

 

OUTPUT2:

 

The person is experienced?

Enter 1 for yes, 0 for no: 1

Enter age of the person: 30

The salary of the person is: 4800

 

 

OUTPUT3:

 

The person is experienced?

Enter 1 for yes, 0 for no: 1

Enter age of the person: 26

The salary of the person is: 3000

 

OUTPUT4:

 

The person is experienced?

Enter 1 for yes, 0 for no: 0

Enter age of the person: 27

The salary of the person is: 2000

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: