Mar 22, 2021 at 1:53pm UTC
i want to Update the program to add a menu for choosing the operation (Search Data, Add a Record, Update Data, Quit)
.......
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
struct Salary
{
float basic_salary;
float deductions;
float bonuses;
float tax;
float net_salary;
};
struct Employee
{
string Name;
int ID;
Salary Sal1;
};
int main()
{
int i;
Employee Emp[3];
for( i=0; i<3; i++)
{
cout<<"Enter the Name of Employee "<<i+1<<": \n";
cin>> Emp[i].Name;
Emp[i].ID=i+1;
cout<<"Enter the basic_salary of Employee "<<i+1<<": \n";
cin>>Emp[i].Sal1.basic_salary;
cout<<"Enter the deductions of Employee "<<i+1<<": \n";
cin>> Emp[i].Sal1.deductions;
cout<<"Enter the bonuses of Employee "<<i+1<<": \n";
cin>> Emp[i].Sal1.bonuses;
if( Emp[i].Sal1.basic_salary<=499)
Emp[i].Sal1.tax=0.0;
else if( Emp[i].Sal1.basic_salary>=500 && Emp[i].Sal1.basic_salary<=800 )
Emp[i].Sal1.tax=0.07*Emp[i].Sal1.basic_salary;
else if( Emp[i].Sal1.basic_salary>=801 && Emp[i].Sal1.basic_salary<=1200)
Emp[i].Sal1.tax=0.10*Emp[i].Sal1.basic_salary;
else
Emp[i].Sal1.tax=0.15*Emp[i].Sal1.basic_salary;
Emp[i].Sal1.net_salary = Emp[i].Sal1.basic_salary + Emp[i].Sal1.bonuses - Emp[i].Sal1.deductions - Emp[i].Sal1.tax;
}
cout<<"Salaries Report"<<endl;
cout<<" ID "<<setw(25)<<" Name "<<setw(25)<<" Basic Salary "<<setw(25)<< " Bonuses " << setw(25)<<" Deductions " <<setw(25) <<" Tax " <<setw(25)<<" Net Salary "<<endl;
cout<< "========================================================================================================================"<<endl;
for( i=0; i<3;i++)
{
cout<<Emp[i].ID<<" "<<setw(25)<<Emp[i].Name<<setw(25)<<Emp[i].Sal1.basic_salary<<setw(25)<< Emp[i].Sal1.bonuses<< setw(25)<<Emp[i].Sal1.deductions <<setw(25) <<Emp[i].Sal1.tax <<setw(25)<<Emp[i].Sal1.net_salary<<endl;
}
cout<<" =========================================================="<<endl;
cout<<" =========================================================="<<endl;
bool found = false;
int Emp_searchid;
cout<<"Enter the Employee ID for searching "<<endl;
cin>> Emp_searchid;
for( i=0; i<3;i++)
if (Emp[i].ID==Emp_searchid)
{found =true; break;}
if (found)
cout<<Emp[i].ID<<" "<<setw(25)<<Emp[i].Name<<setw(25)<<Emp[i].Sal1.basic_salary<<setw(25)<< Emp[i].Sal1.bonuses<< setw(25)<<Emp[i].Sal1.deductions <<setw(25) <<Emp[i].Sal1.tax <<setw(25)<<Emp[i].Sal1.net_salary<<endl;
else
cout<<" The Employee is not found " ;
return 0;
}
Mar 22, 2021 at 5:38pm UTC
abuh ,
PLEASE USE CODE TAGS (the <> formatting button to the right of this box), when posting code.
Along with the proper indenting, it makes it easier to read your code, and thus also easier to respond to your post.
Tutorials on how to use code tags:
http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/
I found the second link to be the most help.
Hint: You can hit "edit post", highlight your code and then press the <> formatting button. This will not automatically indent your code. That part is up to you.
You can use the "preview" button at the bottom to see how it looks.
Additionally, duplicate postings WILL NOT HELP YOU!!! People will think you're a spammer.
Thanks!
max
Edit :
Ok, I have reformatted your program for easier readability.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
struct Salary
{
float basic_salary;
float deductions;
float bonuses;
float tax;
float net_salary;
};
struct Employee
{
string Name;
int ID;
Salary Sal1;
};
int main ()
{
Employee Emp[3];
for (int i = 0; i < 3; i++)
{
cout << "Enter the Name of Employee " << i + 1 << ". \n: " ;
cin >> Emp[i].Name;
Emp[i].ID = i + 1;
cout << "Enter the basic_salary of Employee " << i + 1 << ". \n: " ;
cin >> Emp[i].Sal1.basic_salary;
cout << "Enter the deductions of Employee " << i + 1 << ". \n: " ;;
cin >> Emp[i].Sal1.deductions;
cout << "Enter the bonuses of Employee " << i + 1 << ". \n: " ;
cin >> Emp[i].Sal1.bonuses;
if (Emp[i].Sal1.basic_salary <= 499)
{
Emp[i].Sal1.tax = 0.0;
}
else if (Emp[i].Sal1.basic_salary >= 500 && Emp[i].Sal1.basic_salary <= 800)
{
Emp[i].Sal1.tax = 0.07 * Emp[i].Sal1.basic_salary;
}
else if (Emp[i].Sal1.basic_salary >= 801 && Emp[i].Sal1.basic_salary <= 1200)
{
Emp[i].Sal1.tax=0.10 * Emp[i].Sal1.basic_salary;
}
else
{
Emp[i].Sal1.tax = 0.15 * Emp[i].Sal1.basic_salary;
}
Emp[i].Sal1.net_salary = Emp[i].Sal1.basic_salary + Emp[i].Sal1.bonuses - Emp[i].Sal1.deductions - Emp[i].Sal1.tax;
}
cout << "Salaries Report" << endl;
cout << " ID " << setw(25)
<< " Name " << setw(25)
<< " Basic Salary " << setw(25)
<< " Bonuses " << setw(25)
<< " Deductions " << setw(25)
<< " Tax " << setw(25)
<< " Net Salary " << endl;
cout << "========================================================================================================================" << endl;
for ( int i = 0; i < 3; i++)
{
cout << Emp[i].ID << " " << setw(25)
<< Emp[i].Name << setw(25)
<< Emp[i].Sal1.basic_salary << setw(25)
<< Emp[i].Sal1.bonuses << setw(25)
<< Emp[i].Sal1.deductions << setw(25)
<< Emp[i].Sal1.tax << setw(25)
<< Emp[i].Sal1.net_salary << endl;
}
cout << " ==========================================================" << endl;
cout << " ==========================================================" << endl;
bool found = false ;
int Emp_searchid;
cout << "Enter the Employee ID for searching " << endl;
cin >> Emp_searchid;
for (i = 0; i < 3; i++)
{
if (Emp[i].ID == Emp_searchid)
{
found = true ;
break ;
}
else
{
continue ;
}
}
if (found)
{
cout << Emp[i].ID << " " << setw(25)
<< Emp[i].Name << setw(25)
<< Emp[i].Sal1.basic_salary << setw(25)
<< Emp[i].Sal1.bonuses << setw(25)
<< Emp[i].Sal1.deductions << setw(25)
<< Emp[i].Sal1.tax << setw(25)
<< Emp[i].Sal1.net_salary << endl;
}
else
{
cout << " The Employee is not found. \n" ;
}
return 0;
}
That will make it easier to read your code and help you with it.
Last edited on Mar 22, 2021 at 5:58pm UTC