switch-statement-in-cpp
Hi folks welcome to iTech Apps Lab Blog
This C++ program Demonstrates the use of Switch Statement
Scenario: Calculating salary increment and Tax amount for different Initial Scales
#include <iostream>
using namespace std;
main()
{
//delare and initialize the variables
int sp_scale=0;
int init_sal=0;
int increment_amnt=0;
int updated_sal=0;
int tax_amount=0;
int net_Salary=0;
//showing menu on console
cout<<"************* SALARY CALCULATOR ***************"<<endl;
cout<<"\nSelect a pay scale from the menue : "<<endl;
cout<<"\n************* ***************** ***************"<<endl;
cout<<"\n************* Enter 1 for SPS6 ***************"<<endl;
cout<<"\n************* Enter 2 for SPS7 ***************"<<endl;
cout<<"\n************* Enter 3 for SPS8 ***************"<<endl;
cout<<"\n************* Enter 4 for SPS9 ***************"<<endl;
cin>>sp_scale;
//switch statement to switch between pay scales
switch (sp_scale)
{
case 1:
//calculation
init_sal=40000;
increment_amnt = init_sal * 20/100;
updated_sal = init_sal + increment_amnt;
tax_amount = updated_sal * 3/100;
net_Salary = init_sal + increment_amnt - tax_amount;
//display result
cout <<" Initial Salary: "<< init_sal<<endl;
cout <<" Incremented Salary: "<< increment_amnt<<endl;
cout <<" Increased Salary: "<< updated_sal<<endl;
cout <<" Tax Deduction: "<< tax_amount<<endl;
cout <<" Net Salary: "<< net_Salary<<endl;
break;
case 2:
init_sal=60000;
increment_amnt = init_sal * 15/100;
updated_sal = init_sal + increment_amnt;
tax_amount = updated_sal * 3/100;
net_Salary = init_sal + increment_amnt - tax_amount;
//display result
cout <<" Initial Salary: "<< init_sal<<endl;
cout <<" Incremented Salary: "<< increment_amnt<<endl;
cout <<" Increased Salary: "<< updated_sal<<endl;
cout <<" Tax Deduction: "<< tax_amount<<endl;
cout <<" Net Salary: "<< net_Salary<<endl;
break;
case 3:
init_sal=80000;
increment_amnt = init_sal * 10/100;
updated_sal = init_sal + increment_amnt;
tax_amount = updated_sal * 3/100;
net_Salary = init_sal + increment_amnt - tax_amount;
//display result
cout <<" Initial Salary: "<< init_sal<<endl;
cout <<" Incremented Salary: "<< increment_amnt<<endl;
cout <<" Increased Salary: "<< updated_sal<<endl;
cout <<" Tax Deduction: "<< tax_amount<<endl;
cout <<" Net Salary: "<< net_Salary<<endl;
break;
case 4:
init_sal=100000;
increment_amnt = init_sal * 5/100;
updated_sal = init_sal + increment_amnt;
tax_amount = updated_sal * 3/100;
net_Salary = init_sal + increment_amnt - tax_amount;
//display result
cout <<" Initial Salary: "<< init_sal<<endl;
cout <<" Incremented Salary: "<< increment_amnt<<endl;
cout <<" Increased Salary: "<< updated_sal<<endl;
cout <<" Tax Deduction: "<< tax_amount<<endl;
cout <<" Net Salary: "<< net_Salary<<endl;
break;
default:
cout<<"Your Selected choice doesn't exist'";
}
}
Comments
Post a Comment