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 for the given conditions
To show: if-else statement
Code:
// if-else statement example
#include <iostream>
using namespace std;
int main()
{
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:Code:
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 . . .
Code:
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 . . .