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 " ;
Hint: You can edit your post, highlight your code and 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.
I found the second link to be the most help.
Do you know about functions, do/while and while loops? Since the program does not show muck it helps to know what you can work with.
A few blank lines will help to make your code much easier to read. As an example:
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;
elseif (Emp[i].Sal1.basic_salary >= 500 && Emp[i].Sal1.basic_salary <= 800)
Emp[i].Sal1.tax = 0.07*Emp[i].Sal1.basic_salary;
elseif (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;
}
Also unless there is a good reason for using "float" "double" is the preferred floating point type to use. A more accurate way to work with money is to use "int"s.
Another tip I can give you is the same tip I give to the systems engineer, testing engineer and the program owner at my job, "Could you be more specific of what the problem is to perform the investigation of the defect?" In other words, what is the program doing that is wrong? What are the requirements? What is the code supposed to do? What is the code doing that is not supposed to do? How can you replicate the issue of the code? What I am getting at is the less that you are specific, the more time is wasted going back and forth on trying to figure out what is the issue.
@abuh, @thmm,
I use the clang 10 compiler from 2009 and I had no problem compiling his code using the -std=c++17 flag. Although I think it has had some updates in order to use that flag.
@seeplus,
A tip:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
// To make it easier to read, consider:
for (size_t i = 0; i < MAXEMP; ++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;
}
// instead of
for (size_t i = 0; i < MAXEMP; ++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;
Just a tip, because not many people I know like reading long lines of code that go over into the next line. Just easier to read and visually debug.
Whoops, I meant to say my computer is from 2009, not my compiler. clang 10 was released in 2020, so it's pretty recent. Although you still have to set a dumb flag every time you want to compile something newer than C++11!!!