Question

I want c++ code for employee payslip calculation using switch statement convert this code to switch...

I want c++ code for employee payslip calculation using switch statement

convert this code to switch statement also, use for loop

___________________________________________________________________________

#include

using namespace std;

int main()

{char empname[222];

float basicSalary, h_r_a, DearnessAllow, tax, netSalary;

int e_id;

cout<<"\nEmployee Name :";

cin>>empname;

cout<<"\nEmployee Id :";

cin>>e_id;

cout << "Enter Basic Salary : ";

cin >> basicSalary;

DearnessAllow = 0.30 * basicSalary;

h_r_a= 800;

tax = 0.10 * basicSalary;

netSalary = basicSalary + DearnessAllow + h_r_a - tax;

cout<<"\nEmployee Id              : "<

cout<<"\nEmployee Name            : "<

cout<<"\nBasic Salary             : "<

cout<<"\nHRA                      : "<

cout<<"\nDearnessAllow            : "<

cout<<"\nTax                      : "<

cout<<"\nNet Salary               : "<

return 0;

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

I have written the code using switch statement and also used for loop please consider it .

Code :

#include<bits/stdc++.h>

using namespace std;

int main()

{
char repeat = 'Y';
for (;repeat == 'Y';){

char empname[222];

float basicSalary, h_r_a, DearnessAllow, tax, netSalary;

int e_id;

cout<<"\nEmployee Name :";

cin>>empname;

cout<<"\nEmployee Id :";

cin>>e_id;

cout << "Enter Basic Salary : ";

cin >> basicSalary;

DearnessAllow = 0.30 * basicSalary;

h_r_a= 800;

switch (1)
{
case 1:
if (basicSalary <= 2,50,000)
tax = 0;
case 2:
if (basicSalary > 250000 && basicSalary <= 500000)
tax = 0.05*basicSalary;
case 3:
if (basicSalary > 500000 && basicSalary <= 1000000)
tax = (0.12)*(basicSalary - 500000) + 12500;
case 4:
if (basicSalary > 1000000)
tax = 1,12,500 + 0.30*1000000;

}

netSalary = basicSalary + DearnessAllow + h_r_a - tax;

cout<<"\nEmployee Id : "<<e_id<<endl;

cout<<"\nEmployee Name : "<<empname<<endl;

cout<<"\nBasic Salary : "<<basicSalary<<endl;

cout<<"\nHRA : "<<h_r_a<<endl;

cout<<"\nDearnessAllow : "<<DearnessAllow<<endl;

cout<<"\nTax : "<<tax<<endl;

cout<<"\nNet Salary : "<<netSalary<<endl;
cout<<"Do you want to still continue....Y/N"<<endl;
cin>>repeat;
}

return 0;

}

Screen shots of the code :

#include<bits/stdc++.h> using namespace std; int main() { char repeat = Y; for (; repeat == Y;) { char empname [222]; flocin>>e_id; cout << Enter Basic Salary : ; cin >> basicSalary: DearnessAllow = 0.30 * basicSalary: h_r_a= 800;switch (1) { case 1: if (basicSalary <= 2,50,000) tax = 0; case 2: if (basicSalary > 250000 && basicSalary <= 500000) tax = 0cout<<\nEmployee Id : <<e_id<<endl; cout<<\nEmployee Name H <<empname<<endl; cout<<\nBasic Salary : <<basicSalary<<endl

Screen shots of output :

C:\Users\lenovo\Documents\matrix.exe Employee Name :Onkar Employee Id : 123 Enter Basic Salary : 700000 Employee Id : 123 Emp

If you find anything wrong please mention it in the comments. But please do not give thumbs down. It is my humble request.
HOPE IT SERVED YOUR PURPOSE !!!
PLEASE GIVE THUMBS UP FOR MY ANSWER. I REALLY NEED IT. IT WOULD BE OF GREAT HELP.
THANK YOU.

Add a comment
Know the answer?
Add Answer to:
I want c++ code for employee payslip calculation using switch statement convert this code to switch...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • This C++ program will not let me put numbers in on address, just characters #include using namespace std; float paycalc(){ cout<<"Enter 1 if salary and 2 if hourly: "; int choice, hoursW...

    This C++ program will not let me put numbers in on address, just characters #include using namespace std; float paycalc(){ cout<<"Enter 1 if salary and 2 if hourly: "; int choice, hoursWorked, payrate; float salary; cin>>choice; if(choice == 1){ cout<<"Enter your salary per month: "; cin>>salary; }else{ cout<<"Enter hours worked: "; cin>>hoursWorked; cout<<"Enter pay rate: "; cin>>payrate; salary = hoursWorked * payrate; } return salary; } void printCheck(float sal, int id, char address[30]){ cout<<"Employee id: "<>id; cout<<"Enter address: "; char...

  • // I am going to use if and else stamtents for this employee pay clalulations. //using...

    // I am going to use if and else stamtents for this employee pay clalulations. //using if and else to cal salary //If hours worked is <= 40.0 //Employee salry will = hours*pay rate //else //employess salary will =40*pay rate +(hours worked-40)*1.5* pay rate. #include using namespace std; const double Max_Hours= 40.0; const double MuLTIPLER = 1.5; char salary; char payrate; char hours_worked; char Max_hours; char get_total_pay; int main() { double Hours=0; double Payrate = 0; cout <<"Please enter employee...

  • Code is in C++: Im wondering how i can make the program continue to ask the...

    Code is in C++: Im wondering how i can make the program continue to ask the user to enter Y/N with the if statment. Is it possible with an If statment? #include <iostream> using namespace std; int main() { float usDollars,cYuan; float *Dollars; char choice; Dollars = &usDollars; while(usDollars >= 0){ cout <<"Enter the amount in U.S Dollars: "; cin >> usDollars; cout << usDollars<< " U.S Dollar in Chinese Yuan is :"<<*Dollars*7.09<<endl; if (choice == 'y' || choice ==...

  • Write following program using Switch statement. #include <iostream> using namespace std; int main() int number; cout...

    Write following program using Switch statement. #include <iostream> using namespace std; int main() int number; cout << "Enter an integer cin >> number; if (number > B) cout << You entered a positive integer: " << number << endl; else if (number (8) cout<<"You entered a negative integer: " << number << endl; cout << "You entered e." << endl; cout << "This line is always printed." return 0;

  • Convert the below code into if else selection: #include <iostream> using namespace std; int main() {...

    Convert the below code into if else selection: #include <iostream> using namespace std; int main() { int num; sin. >> num; switch (num) { case 1: cout << "Casel: Value is: << num << endl; break; case 2: break; case 3: cout << "Case3: Value is: " << num << endl; break; default: cout << "Default: Value is: << num << endl; break; } return; }

  • C++ class 3.2.4: If-else statement: Fix errors. Re-type the code and fix any errors. The code...

    C++ class 3.2.4: If-else statement: Fix errors. Re-type the code and fix any errors. The code should convert non-positive numbers to 1. if (userNum > 0) cout << "Positive." << endl; else cout << "Not positive, converting to 1." << endl; Answer #include using namespace std; int main() { int userNum; cin >> userNum; /* Your solution goes here */ return 0; userNum = 1; cout << "Final: " << userNum << endl;

  • I need to add a for or a while loop to the following code. please help...

    I need to add a for or a while loop to the following code. please help needs to be in c++. #include <iostream> #include <string.h> using namespace std; int main() {    char input[100]; cout << "Please enter a character string: "; cin >> input; char *head = &input[0], *tail = &input[strlen(input) - 1]; char temp = *head; *head = *tail; *tail = temp; tail--; head++; cout << "CString = " << input << "\n"; }

  • Could use some help with this, Instructions: You will need to add an input statement for...

    Could use some help with this, Instructions: You will need to add an input statement for the grade variable to this code. Also add a for loop so that you can enter more than one grade. Code the for loop so that at least 7 grades can be entered. #include <iostream> #include <string> using namespace std; void main() {      char grade;           for (int x = 0; x < 7; x++)      {            cout << "Enter a...

  • I have written my code for an employee management system that stores Employee class objects into...

    I have written my code for an employee management system that stores Employee class objects into a vector, I am getting no errors until I try and compile, I am getting the error: C2679 binary '==': no operator found which takes a right-hand operand of type 'const std::string' (or there is no acceptable conversion). But I am not sure why any help would be great, Thank you! 1 2 3 4 5 6 7 8 9 10 11 12 13...

  • This is c++ programming and here is my code. I am getting an exception thrown on...

    This is c++ programming and here is my code. I am getting an exception thrown on the destructor for permanentworker. Can you tell me why I am getting this exception? #include <iostream> #pragma warning(disable:4996) class PermanentWorker { private:    char *name;    int salary; public:    PermanentWorker(const char* nam, int money) : salary(money)    {        name = new char[strlen(nam) + 1];        strcpy(name, nam);    }    int getPay() const    {        return salary;   ...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT