Apr 2, 2015 at 10:14pm UTC
The program below is one made for a weekly budget after gross pay has been calculated and taxes have been deducted. Information has been given to create a file and then later reopen it and read the data. I am having trouble with the program reading the data from the created file and executing it. (This is not a finalized version, it still needs work, although i cant get the program to output any data other than "10000".) Would appreciate the help. (This is a basic learning programming which can contain up to functions, no advanced programming please.)
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
int main()
{
ofstream outputFile;
outputFile.open("Information");
cout << "File is being written" << endl;
outputFile << "1 JR 35 10 3" << endl;
outputFile << "2 TE 41 15 0" << endl;
outputFile << "3 RP 40 12.75 5" << endl;
outputFile << "4 TC 30 15 0" << endl;
outputFile << "5 JP 39 10.5 4" << endl;
outputFile << "6 CT 50 21.5 3" << endl;
outputFile << "7 ZP 45 12.75 5" << endl;
outputFile << "8 RM 40 10.75 2" << endl;
outputFile << "9 JA 40 10 0" << endl;
outputFile << "10 ZZ 24 15.75 3" << endl;
outputFile.close();
cout << "Program has been written";
return 0;
}
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
double Calc_Tax_Rate(int Depend);
int main()
{
int ID, Name, Depend;
double Hours, Pay_Rate, Gross_Pay, Total_Ded, Net_Pay;
double FICA_Amount, INS_Amount, Retire_Amount, WH_Amount, OverTime, OverTime_Pay;
double FICA_Rate = 0.675, INS_Rate = 0.15, Retire_Rate = 0.325;
ifstream inputFile;
inputFile.open("Information.txt");
if (inputFile)
{
while(inputFile >> ID)
{
inputFile >> Name;
inputFile >> Hours;
inputFile >> Pay_Rate;
inputFile >> Depend;
if(Hours > 40)
{
OverTime = Hours - 40;
OverTime_Pay = OverTime * 1.5;
Gross_Pay =+ OverTime_Pay;
}
Gross_Pay = Hours * Pay_Rate;
FICA_Amount = Gross_Pay * FICA_Rate;
INS_Amount = Gross_Pay * INS_Rate;
Retire_Amount = Gross_Pay * Retire_Rate;
WH_Amount = Gross_Pay * Calc_Tax_Rate(Depend);
Total_Ded = FICA_Amount + INS_Amount + Retire_Amount + WH_Amount;
Net_Pay = Gross_Pay - Total_Ded;
cout << ID;
cout << Name;
cout << Gross_Pay;
cout << Total_Ded;
cout << Net_Pay;
}
}
else
{
cout << "Error Open File";
}
return 0;
}
double Calc_Tax_Rate(int Depend)
{
if (Depend = 0)
{
return 0.30;
}
else if (Depend >= 1 || Depend <= 3)
{
return 0.25;
}
else if (Depend >= 4)
{
return 0.20;
}
}