Determining the post promotion based on current post, year served and the number of publication in C++ using the nested if-else statement

 

Compiler: Visual C++ Express Edition 2005

Compiled on Platform: Windows XP Pro SP2

Header file: Standard

Additional project setting: Set project to be compiled as C++

Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C++ Code (/TP)

Other info: none

To do: Determining the post promotion based on current post, year served and the number of publication in C++ using the nested if-else statement

To show: How to use the nested if-else-if statement to determine the post promotion based on current post, year served and the number of publication in C++ programming

 

// selecting options using if-else-if C++ example

#include <iostream>

using namespace std;

 

int main(void)

{

char job_title;

 

int years_served, no_of_pub;

cout<<"Enter data \n";

cout<<"Current job (Tutor-T, lecturer-L, Assoc prof-A): ";

cin>>job_title;

cout<<"Years served: ";

cin>>years_served;

cout<<"No of publication: ";

cin>>no_of_pub;

 

if(job_title == 'T' || 't')

{

if(years_served > 15)

if(no_of_pub > 10)

cout<<"\nPromote to lecturer";

else

cout<<"\nMore publications required";

else

cout<<"\nMore service required";

}

else if(job_title == 'L' || 'l')

{

if(years_served > 10)

if(no_of_pub > 5)

cout<<"\nPromote to Assoc professor";

else

cout<<"\nMore publications required";

else

cout<<"\nMore service required";

}

else if(job_title == 'A' || 'a')

{

if(years_served > 5)

if(no_of_pub > 5)

cout<<"\nPromote to professor";

else

cout<<"\nMore publications required";

else

cout<<"\nMore service required";

}

cout<<"\n";

return 0;

}

 

Output example:

 

Enter data

Current job (Tutor-T, lecturer-L, Assoc prof-A): T

Years served: 3

No of publication: 4

More service required

Press any key to continue . . .

 

Enter data

Current job (Tutor-T, lecturer-L, Assoc prof-A): A

Years served: 15

No of publication: 15

Promote to professor

Press any key to continue . . .

 

 

C and C++ Programming Resources | C & C++ Code Example Index