Determining the benefits based on the job profile C++ program sample using 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 benefits based on the job profile C++ program sample using if-else statement

To show: How to use the if-else statement to determine the remuneration based on the job profile in C++ programming

 

// the if-else statement C++ example

#include <iostream>

using namespace std;

 

int main(void)

{

int job_code;

 

double housing_allowance, entertainment_allowance, car_allowance;

cout<<"Available job codes: 1 or non 1:\n"<<endl;

cout<<"Enter job code: ";

cin>>job_code;

 

// if 1 is selected

if(job_code==1)

{

car_allowance = 200.00;

housing_allowance = 800.00;

entertainment_allowance = 250.00;

cout<<"--THE BENEFITS--\n";

cout<<"Car allowance: "<<car_allowance<<endl;

cout<<"Housing allowance: "<<housing_allowance<<endl;

cout<<"Entertainment allowance: "<<entertainment_allowance<<endl;

}

// other than 1

else

{

car_allowance = 100.00;

housing_allowance = 400.00;

entertainment_allowance = 150.00;

cout<<"--THE BENEFITS--\n";

cout<<"Car allowance: "<<car_allowance<<endl;

cout<<"Housing allowance: "<<housing_allowance<<endl;

cout<<"Entertainment allowance: "<<entertainment_allowance<<endl;

}

return 0;

}

 

Output example:

 

Available job codes: 1 or non 1:

Enter job code: 1

--THE BENEFITS--

Car allowance: 200

Housing allowance: 800

Entertainment allowance: 250

Press any key to continue . . .

 

Available job codes: 1 or non 1:

Enter job code: 3

--THE BENEFITS--

Car allowance: 100

Housing allowance: 400

Entertainment allowance: 150

Press any key to continue . . .

 

 

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