Я бился головой об этом в течение большей части 2 дней, и я, кажется, свел все до одной оставшейся ошибки. Я не могу найти ответы на этот конкретный случай в Интернете.
Я потратил много времени, пытаясь переопределить некоторые вещи, не нарушая весь код, и ничего не получил. Я надеюсь, что это достаточно хорошо прокомментировано, чтобы его можно было прочитать.
#include <iostream>
#include "stdafx.h"
#include <fstream>
#include <string>
#include <array>
using namespace std;
ifstream fin;
//Defining Global Variables
float employeeID[100];
float hoursWorked[100];
float hourlyRate[100];
float overtimeHours[100];
float grossPay[100];
float netPay[100];
float overtimePay[100];
float regularPay[100];
float taxesPaid[100];
char maritalStatus[100];
string firstName[100];
string lastName[100];
int writingToArrays()
{
//Readying File
ifstream inFile;
inFile.open("employee.txt");
//Checking File
if (!inFile)
{
cerr << "File not found.\n";
system("PAUSE");
return 0;
}
//Loop Parameters
int i = 0;
//Reading File and Writing to Arrays
while (inFile >> firstName[i] >> lastName[i] >> maritalStatus[i] >> employeeID[i] >> hoursWorked[i] >> hourlyRate[i])
{
i++;
}
return 0;
}
float overtimeAndPayFunction(float hourlyRate[i], float hoursWorked[i])
{
if (hoursWorked[i] > 40)
{
overtimeHours[i] = hoursWorked[i] - 40;
overtimePay[i] = overtimeHours[i] * hourlyRate[i] * 1.5;
grossPay[i] = (hourlyRate[i] * 40) + overtimePay[i];
regularPay[i] = grossPay[i] - overtimePay[i];
}
else
{
overtimeHours[i] = 0;
overtimePay[i] = 0;
grossPay[i] = hourlyRate[i] * hoursWorked[i];
regularPay[i] = grossPay[i] - overtimePay[i];
}
i++;
return overtimeHours[i], overtimePay[i], grossPay[i], regularPay[i];
}
float netPayAndTaxFunction(char maritalStatus[i], float grossPay[i])
{
float taxesPaid[100];
//Nested If Statements to Find Tax Rate Based on Marital Status
//Single
if (maritalStatus[i] == 'S' || maritalStatus[i] == 's')
{
if (grossPay[i] <= 500)
{
taxesPaid[i] = grossPay[i] * 0.05;
netPay[i] = grossPay[i] - taxesPaid[i];
}
else if (grossPay[i] <= 800)
{
taxesPaid[i] = grossPay[i] * .15;
netPay[i] = grossPay[i] - taxesPaid[i];
}
else if (grossPay[i] <= 1000)
{
taxesPaid[i] = grossPay[i] * .25;
netPay[i] = grossPay[i] - taxesPaid[i];
}
else
{
taxesPaid[i] = grossPay[i] * .35;
netPay[i] = grossPay[i] - taxesPaid[i];
}
}
//Married
else if (maritalStatus[i] == 'm' || maritalStatus[i] == 'M')
{
if (grossPay[i] <= 500)
{
taxesPaid[i] = grossPay[i] * 0;
netPay[i] = grossPay[i] - taxesPaid[i];
}
else if (grossPay[i] <= 800)
{
taxesPaid[i] = grossPay[i] * .1;
netPay[i] = grossPay[i] - taxesPaid[i];
}
else if (grossPay[i] <= 1000)
{
taxesPaid[i] = grossPay[i] * .2;
netPay[i] = grossPay[i] - taxesPaid[i];
}
else
{
taxesPaid[i] = grossPay[i] * .3;
netPay[i] = grossPay[i] - taxesPaid[i];
}
}
//Head of Household
else if (maritalStatus[i] == 'H' || maritalStatus[i] == 'h')
{
if (grossPay[i] <= 500)
{
taxesPaid[i] = grossPay[i] * 0;
netPay[i] = grossPay[i] - taxesPaid[i];
}
else if (grossPay[i] <= 800)
{
taxesPaid[i] = grossPay[i] * .05;
netPay[i] = grossPay[i] - taxesPaid[i];
}
else if (grossPay[i] <= 1000)
{
taxesPaid[i] = grossPay[i] * .15;
netPay[i] = grossPay[i] - taxesPaid[i];
}
else
{
taxesPaid[i] = grossPay[i] * .25;
netPay[i] = grossPay[i] - taxesPaid[i];
}
}
return taxesPaid[i], netPay[i];
}
void outputFunction(string firstName[i], string lastName[i], char maritalStatus[i], float hoursWorked[i], float hourlyRate[i], float employeeID[i], float overtimeHours[i], float overtimePay[i], float taxesPaid[i], float regularPay[i], float grossPay[i], float netPay[i])
{
//Output Header
cout << "\nWelcome to Dr. Ebrahimi Inc. Payroll System\n";
cout << "\nFirst Last MS ID HW HR OTH OTP REGP GROSS TAX NET";
cout << "\n======== ======== == ==== ==== ==== ==== ======= ======= ======= ===== =======";
//Outputing the Employees Information
cout << "\n";
cout << firstName[i] << " " << lastName[i];
cout << " " << maritalStatus[i] << " ";
cout << employeeID[i] << " ";
//Formatting and Outputting the Hours Worked
if (hoursWorked[i] < 10.00)
{
cout << hoursWorked[i] << " ";
}
else
{
cout << hoursWorked[i] << " ";
}
//Formatting and Outputting the Hourly Rate
if (hourlyRate[i] < 10.00)
{
cout << hourlyRate[i] << " ";
}
else
{
cout << hourlyRate[i] << " ";
}
//Formatting and Outputting Overtime Hours
if (overtimeHours[i] != 0.00)
{
if (overtimeHours[i] < 10.00)
{
cout << " " << overtimeHours[i] << " ";
}
else
{
cout << " " << overtimeHours[i] << " ";
}
}
else
{
cout << " N/A ";
}
//Formatting and Outputting Overtime Pay
if (overtimePay[i] != 0.00)
{
if (overtimePay[i] < 10.00)
{
cout << overtimePay[i] << " ";
}
else if (overtimePay[i] < 100.00)
{
cout << overtimePay[i] << " ";
}
else if (overtimePay[i] < 1000.00)
{
cout << overtimePay[i] << " ";
}
else
{
cout << overtimePay[i] << " ";
}
}
else
{
cout << "N/A ";
}
//Formatting and Outputting Regular Pay
if (regularPay[i] < 10)
{
cout << regularPay[i] << " ";
}
else if (regularPay[i] < 100)
{
cout << regularPay[i] << " ";
}
else if (regularPay[i] < 1000)
{
cout << regularPay[i] << " ";
}
else
{
cout << regularPay[i] << " ";
}
//Formatting and Outputting Gross Pay
if (grossPay[i] < 10)
{
cout << grossPay[i] << " ";
}
else if (grossPay[i] < 100)
{
cout << grossPay[i] << " ";
}
else if (grossPay[i] < 1000)
{
cout << grossPay[i] << " ";
}
else
{
cout << grossPay[i] << " ";
}
//Formatting and Outputting Taxes Paid
if (taxesPaid[i] < 10)
{
cout << taxesPaid[i] << " ";
}
else if (taxesPaid[i] < 100)
{
cout << taxesPaid[i] << " ";
}
else if (taxesPaid[i] < 1000)
{
cout << taxesPaid[i] << " ";
}
else
{
cout << taxesPaid[i] << " ";
}
//Formatting and Outputting Net Pay
if (netPay[i] < 10)
{
cout << netPay[i] << " ";
}
else if (netPay[i] < 100)
{
cout << netPay[i] << " ";
}
else if (netPay[i] < 1000)
{
cout << netPay[i] << " ";
}
else
{
cout << netPay[i] << " ";
}
//Incrementing While Loop
i++;
}
int main()
{
//Open File and Write to Arrays
writingToArrays();
//Loop Parameters
int i = 0;
int length = *(&hoursWorked + 1) - hoursWorked;
while ( i < length )
{
//Calling Function
overtimeAndPayFunction(hourlyRate[i], hoursWorked[i]);
//Calling Function
netPayAndTaxFunction(maritalStatus[i], grossPay[i]);
//Calling Function
outputFunction(firstName[i], lastName[i], maritalStatus[i], hoursWorked[i], hourlyRate[i], employeeID[i], overtimeHours[i], overtimePay[i], taxesPaid[i], regularPay[i], grossPay[i], netPay[i]);
//Looping Function Calls
i++;
}
//Ending Program
cout << "\n";
system("PAUSE");
}
Я получаю ошибку: error C2065: 'i': undeclared identifier
Предполагается, что таблица будет выглядеть следующим образом (baseданные высасываются из файла):
First Last MS ID HW HR OTH OTP REGP GROSS TAX NET
======== ======== == ==== ==== ==== ==== ======= ======= ======= ===== =======
Janice Trent S 1111 10 10 N/A N/A 100 100 5 95
Krystina Gibbs M 2222 41 12 1 18 480 498 0 498
Francine Kagern h 3333 7 40 N/A N/A 280 280 0 280