Can some help me fix my code Final.cpp

#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <iomanip>



using namespace std;

const double FedTaxRate = .08;//Federal taxe rate

const double StateTaxRate = .03;// State taxe rate

const double SocialSecurityTax = .02;//Social Security Tax for people that make less than $30,00 total gross for the year

float TD;//Total deductions

double deductionsfn(double GP, float StateTax, float FedTax, double yearDG);

int main(void)

{

string filename;

ifstream infile;

//Variables

string Ln[10];//Lastname

string Fn[10];//Firstname

char PT[10];//Pay Type

double RS[10];// Rate/Salary

double yearDG[10];//Year to Date Gross

double rate[10];//Pay Rate

double GP[10];//Gross Pay

double OP;//Overtime Pay

double OW;//Oevertime Wage

double NW;//Normal Wage

double hrs;//hours worked

int i;//counter

int number;//of people

int choice;//Which one they want to pick

double deductions[10];

int name;

cout << "Enter File Name: ";

getline(cin, filename);

//Opening the file for reading

infile.open(filename.c_str());

if (!infile)

{

cout << "Error could not open file";

}

do
{

cout << "Which one would you like to perform?" << endl;

cout << "1. Weekly Payroll Report" << endl;

cout << "2. Pay Rate/Salary Report" << endl;

cout << "3. Exit" << endl;

}
while (i = 0; i <= 10; i++)
{

case(PT[i] == 'S')
{

GP[i]

}

name = (Ln[i] + ", " + Fn[i]);

case (PT[i] == 'H')

{

cout << name << endl;

cout << "How many hours did they work? ";

cin >> hrs;
}
if (hrs <= 40)

{

GP[i] = hrs * rate[i]

}

else if (hrs > 40)

{

NW = 40 * rate[i]

OP = 1.5 * rate[i]

OW = OP * (hrs - 40)

GP[i] = NW + OW

}

}



for (i = 0; i < number; i++)

{
deductions[i] = deductionsfn(double GP, float FedTax, float StateTax, double yearDG);

}

for (i = 0; i < number; i++)

{

ofstream.outputfile;

}
return 0;
}

double deductionsfn(double GP, float FedTax, float StateTax, double yearDG)
{

float FedTax;//Federal tax amount

float StateTax;//State tax amount

float SS;//Social Security tax amount

float TD;//Total deductions


for (i = 0; i <= 10; i++)

{

if (yearDG[i] < 30000)

{

FedTax = GP * FedTaxRate

StateTax = GP * StateTaxRate

SS = GP * SocialSecurityTax

TD = StateTax + FedTax + SS

}

else (yearDG[i] >= 30000)

{

FedTax = GP * FedTaxRate

StateTax = GP * StateTaxRate

TD = StateTax + FedTax

}

}
return TD;
}
Last edited on
Can some help me fix my code Final.cpp
Without knowing what it's supposed to do, how can we fix it? Please post a description of what the code is supposed to do.

Don't double space your code. It just makes you (and me) scroll up and down a lot more.

Please use code tags. When posting code, highlight the code, then click the <> button to the right of the edit window.

Okay, after looking at your code and reformatting it, it looks like you're doing some sort of payroll system. The good new is that the most of the logic that you need is in your code, it's just full of syntax errors.

Remember that statements end with a semicolon. You've missed this many times.

Here is a version of your code that compiles but definitely does NOT work. Once you post a description of what it's supposed to do, I think we can figure out how to fix it.

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
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <iomanip>

using namespace std;

const double FedTaxRate = .08;	//Federal taxe rate
const double StateTaxRate = .03;	// State taxe rate
const double SocialSecurityTax = .02;	//Social Security Tax for people that make less than $30,00 total gross for the year

float TD;			//Total deductions

double deductionsfn(double GP, double yearDG);

int
main(void)
{

    string filename;
    ifstream infile;

    //Variables
    string Ln[10];		//Lastname
    string Fn[10];		//Firstname
    char PT[10];		//Pay Type
    double RS[10];		// Rate/Salary
    double yearDG[10];		//Year to Date Gross
    double rate[10];		//Pay Rate
    double GP[10];		//Gross Pay
    double OP;			//Overtime Pay
    double OW;			//Oevertime Wage
    double NW;			//Normal Wage
    double hrs;			//hours worked
    int i;			//counter
    int number;			//of people
    int choice;			//Which one they want to pick
    double deductions[10];
    string name;

    cout << "Enter File Name: ";
    getline(cin, filename);

    //Opening the file for reading
    infile.open(filename.c_str());
    if (!infile) {
	cout << "Error could not open file";
    }
    {
	cout << "Which one would you like to perform?" << endl;
	cout << "1. Weekly Payroll Report" << endl;
	cout << "2. Pay Rate/Salary Report" << endl;
	cout << "3. Exit" << endl;
    }

    for (i = 0; i <= 10; i++) {
	name = (Ln[i] + ", " + Fn[i]);
	if (PT[i] == 'S') {
	    GP[i] = RS[i];
	} else if (PT[i] == 'H') {
	    cout << name << endl;
	    cout << "How many hours did they work? ";
	    cin >> hrs;

	    if (hrs <= 40) {
		GP[i] = hrs * rate[i];
	    } else if (hrs > 40) {
		NW = 40 * rate[i];
		OP = 1.5 * rate[i];
		OW = OP * (hrs - 40);
		GP[i] = NW + OW;
	    }
	}
	deductions[i] = deductionsfn(GP[i], yearDG[i]);
    }
    for (i = 0; i < number; i++) {
	ofstream outputfile;
    }
    return 0;
}


double deductionsfn(double GP, double yearDG)
{
    float FedTax;		//Federal tax amount
    float StateTax;		//State tax amount
    float SS;		//Social Security tax amount
    float TD;		//Total deductions

    for (int i = 0; i <= 10; i++) {
	if (yearDG < 30000) {
	    FedTax = GP * FedTaxRate;
	    StateTax = GP * StateTaxRate;
	    SS = GP * SocialSecurityTax;
	    TD = StateTax + FedTax + SS;
	} else if (yearDG >= 30000) {
	    FedTax = GP * FedTaxRate;
	    StateTax = GP * StateTaxRate;
	    TD = StateTax + FedTax;
	}
    }
    return TD;
}
Topic archived. No new replies allowed.