i read from a file okay
for each line i save the respective data into their respective variables
i output each variable to see if the data has really been saved.(is has)
but when i try using the if condition to check the variable and perform a function
it doesn't work and always go to the last else condition and displays "Not Working", Please Help.
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
int nEmployeeNumber = 0;
char strEmployeeName[128];
float fHourlyRate = 0.00;
float nNoofhoursPerWeek = 0.00;
string strEmployeeCategory;
float fOvertime = 0.00;
float fSalary = 0.00;
float fTotalIncome = 0.00;
float fNetIncome = 0.00;
float fTax = 0.00;
ifstream empin;
empin.open("employees.txt", ios::in);
if(empin >> nEmployeeNumber >> strEmployeeName >> fHourlyRate >> nNoofhoursPerWeek >> strEmployeeCategory)
{
cout << nEmployeeNumber << " " << strEmployeeName << " " << fHourlyRate << " " << nNoofhoursPerWeek << " " << strEmployeeCategory << endl;
if(nNoofhoursPerWeek > 40.00 && strEmployeeCategory == "J")
{
fOvertime = nNoofhoursPerWeek - 40.00;
fOvertime = fOvertime * (fHourlyRate * 1.5);
cout << fOvertime << endl;
fSalary = fHourlyRate * nNoofhoursPerWeek * 4.00;
cout << fSalary;
fTotalIncome = fSalary + fOvertime;
cout << fTotalIncome << endl;
if(fTotalIncome > 1000)
{
fTax = (17/100) * fTotalIncome;
cout << fTax << endl;
}
else if(fTotalIncome <= 1000)
{
fTax = (10/100) * fTotalIncome;
cout << fTax << endl;
}
fNetIncome = fTotalIncome - fTax;
cout << "\n";
}
else if(nNoofhoursPerWeek == 40)
{
fSalary = fHourlyRate * nNoofhoursPerWeek * 4;
cout << fSalary << endl;
fTotalIncome = fSalary + fOvertime;
cout << fTotalIncome << endl;
if(fTotalIncome > 1000)
{
fTax = (17/100) * fTotalIncome;
cout << fTax << endl;
}
if(fTotalIncome <= 1000)
{
fTax = (10/100) * fTotalIncome;
cout << fTax << endl;
}
fNetIncome = fTotalIncome - fTax;
cout << fNetIncome << endl;
cout << "\n";
}
else
{
cout << "Not Working" << endl;
}
ofstream empout;
empout.open("employees_out.txt", ios::out | ios::app);
if(empout.good())
{
empout << nEmployeeNumber << " " << strEmployeeName << " " << fHourlyRate << " " << nNoofhoursPerWeek << " " << strEmployeeCategory << " " << fOvertime << " " << fTotalIncome << " " << fTax << " " << fNetIncome << " " << endl;
empout.flush();
}
empout.close();
}
empin.close();
return 0;
}