Calculating Gross Pay - Arrays

I have started to learn C++ and have come to this forum many times from google searches, here is my problem, I am just learning arrays, I modified my program to use arrays but now it wont calculate the gross pay well it seems it does but not correctly. The gross pay is coming back as "-9.25596e+061" it worked fine before I added arrays can someone point me in the right direction? I do have a text file with the following input
John Doe 1404 45 20 H
Bobby Jill 1404 45 20 S


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
#include <iostream>		//including library (directive header file)
#include <windows.h>	//makes console look pretty
#include <fstream>		//Library to read files
#include <iomanip>
using namespace std;

int main() {
	SetConsoleTitleW(L"Payroll System");	//Set Console Title

	ifstream input;
	input.open("numemployees4.txt"); //Opens the file
	char ms[6] = {'H', 'h', 'M', 'M', 'S', 's'};
	char employeeid[100][12];
	char firstname[100][14], lastname[100][15];
	int hoursworked[100];
	double hourlyrate[100], grosspay[100], taxamount[100], taxrate[100], netpay[100], ot[100], otpay[100], regpay[100];
	int counter = 0;
	int i;
	

	while (input >> firstname[counter]>> lastname[counter]>> employeeid[counter] >> hoursworked[counter] >> hourlyrate[counter] >> ms[100])
		counter = counter + 1;
		for (i = 0; i < counter; i++){
			if (hoursworked[i] > 40)
			ot[i] = hoursworked [i] - 40;
			otpay[i] = ot[i] * hourlyrate[i] * 1.5;
			regpay [i] = 40 * hourlyrate[i];
		}

		if (ot[i] = 0){
			otpay[i] = 0;
			regpay [i] = hoursworked[i] * hourlyrate[i];
		}

		for (i = 0, i < counter; i++;) {
		grosspay[i] = regpay[i] + otpay[i] ;
		}

			for (i = 0; i < counter; i++){

			if (grosspay[i] > 1000)
				taxrate[i] = 0.30;
			
			else if (grosspay [i] > 800)
				taxrate [i] = 0.20;
			
			else if (grosspay [i] > 500)
				taxrate[i] = 0.10;
	} 
		for (i = 0; i < counter; i++){

			if (ms[i] == 's' || ms[i] == 'S')
			taxrate[i] = taxrate[i] + 0.05;
			
		else if (ms[i] == 'h' || ms[i] == 'H')
			taxrate[i] = taxrate[i] - 0.05;
		
		else if (ms[i] == 'm' || ms[i] == 'M')
			taxrate[i] = taxrate[i];
		}
		
		for (i = 0; i < counter; i++){
			taxamount[i] = grosspay[i] * taxrate[i];
		}
		for (i = 0; i < counter; i++){
			netpay[i] = grosspay[i] - taxamount[i];
		}
			
		
		cout << setw(7) << "FIRST NAME" <<setw(14)<< "LAST NAME"<<setw(14)<< "EMPLOYEE ID" << setw(7) << "STAT" << setw(14) << "HOURS WORKED" << setw(14) << "GROSS PAY" <<endl << endl;
		
		for (i=0; i<counter; i++){

			cout<< setw(7)<< firstname[i] << setw(14)<< lastname[i]<< setw(14)<< employeeid[i]<< setw(7)<< ms[counter] <<setw(14)<< hoursworked[i] <<setw(14)<<grosspay[i]<<endl;
		}
		cout << "\n";								 //Creates 	space

	
	input.close(); //Closes the open file
	//system("pause");
	return 0;

}
A few typos in your code, I've added comments. Just for fun I've also simplified it a little in the second post, as you have way more loops than you need.
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
#include <iostream>		//including library (directive header file)
#include <windows.h>	//makes console look pretty
#include <fstream>		//Library to read files
#include <iomanip>
using namespace std;

int main() {
	SetConsoleTitleW(L"Payroll System");	//Set Console Title

	ifstream input;
	input.open("numemployees4.txt"); //Opens the file
	char ms[100];
	char employeeid[100][12];
	char firstname[100][14], lastname[100][15];
	int hoursworked[100] = {0}; // initialise
	double hourlyrate[100] = {0.0}, grosspay[100] = {0.0}, taxamount[100] = {0.0}, taxrate[100] = {0.0}, netpay[100] = {0.0}, ot[100] = {0.0}, otpay[100] = {0.0}, regpay[100] = {0.0};  // initialise
	int counter = 0;
	int i;
	

	while (input >> firstname[counter]>> lastname[counter]>> employeeid[counter] >> hoursworked[counter] >> hourlyrate[counter] >> ms[counter])
		counter = counter + 1;
		for (i = 0; i < counter; i++){
			if (hoursworked[i] > 40)
			ot[i] = hoursworked [i] - 40;
			otpay[i] = ot[i] * hourlyrate[i] * 1.5;
			regpay [i] = (hoursworked[i] - ot[i]) * hourlyrate[i]; // what if hours worked less than 40?
		}

		// this block is no longer needed
		//also this whole block is outside the loop
		if (ot[i] == 0){ // typo  = instead of ==
			otpay[i] = 0;
			regpay [i] = hoursworked[i] * hourlyrate[i];
		}

		for (i = 0; i < counter; i++) { //typo , instead of ; also shouldn't have a ; after i++
		grosspay[i] = regpay[i] + otpay[i] ;
		}

			for (i = 0; i < counter; i++){

			if (grosspay[i] > 1000)
				taxrate[i] = 0.30;
			
			else if (grosspay [i] > 800)
				taxrate [i] = 0.20;
			
			else if (grosspay [i] > 500)
				taxrate[i] = 0.10;
	} 
		for (i = 0; i < counter; i++){

			if (ms[i] == 's' || ms[i] == 'S')
			taxrate[i] = taxrate[i] + 0.05;
			
		else if (ms[i] == 'h' || ms[i] == 'H')
			taxrate[i] = taxrate[i] - 0.05;
		
		else if (ms[i] == 'm' || ms[i] == 'M')
			taxrate[i] = taxrate[i]; // why?
		}
		
		for (i = 0; i < counter; i++){
			taxamount[i] = grosspay[i] * taxrate[i];
		}
		for (i = 0; i < counter; i++){
			netpay[i] = grosspay[i] - taxamount[i];
		}
			
		
		cout << setw(7) << "FIRST NAME" <<setw(14)<< "LAST NAME"<<setw(14)<< "EMPLOYEE ID" << setw(7) << "STAT" << setw(14) << "HOURS WORKED" << setw(14) << "GROSS PAY" <<endl << endl;
		
		for (i=0; i<counter; i++){

			cout<< setw(7)<< firstname[i] << setw(14)<< lastname[i]<< setw(14)<< employeeid[i]<< setw(7)<< ms[counter] <<setw(14)<< hoursworked[i] <<setw(14)<<grosspay[i]<<endl;
		}
		cout << "\n";								 //Creates 	space

	
	input.close(); //Closes the open file
	//system("pause");
	return 0;

}


Output:
FIRST NAME     LAST NAME   EMPLOYEE ID   STAT  HOURS WORKED     GROSS PAY

   John           Doe          1404                  45           950
  Bobby          Jill          1404                  45           950

Simplified version:
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
#include <iostream>		//including library (directive header file)
#include <windows.h>	//makes console look pretty
#include <fstream>		//Library to read files
#include <iomanip>
using namespace std;

int main() {
	SetConsoleTitleW(L"Payroll System");	//Set Console Title

	ifstream input;
	input.open("numemployees4.txt"); //Opens the file
	char ms[100] = {0};
	char employeeid[100][12];
	char firstname[100][14], lastname[100][15];
	int hoursworked[100] = {0}; 
	double hourlyrate[100] = {0.0}, grosspay[100] = {0.0}, taxamount[100] = {0.0}, taxrate[100] = {0.0}, netpay[100] = {0.0}, ot[100] = {0.0}, otpay[100] = {0.0}, regpay[100] = {0.0}; 
	int i = 0;
	cout << setw(7) << "FIRST NAME" <<setw(14)<< "LAST NAME"<<setw(14)<< "EMPLOYEE ID" << setw(7) << "STAT" << setw(14) << "HOURS WORKED" << setw(14) << "GROSS PAY" << setw(12) << "NET PAY" << setw(12) << "TAX" << endl << endl;
	while (input >> firstname[i]>> lastname[i]>> employeeid[i] >> hoursworked[i] >> hourlyrate[i] >> ms[i])
	{
			if (hoursworked[i] > 40)
			{
				ot[i] = hoursworked [i] - 40;
			}
			
			otpay[i] = ot[i] * hourlyrate[i] * 1.5;
			regpay [i] = (hoursworked[i] - ot[i]) * hourlyrate[i]; 
			grosspay[i] = regpay[i] + otpay[i];
			if (grosspay[i] > 1000)
			{
				taxrate[i] = 0.30;
			}			
			else if (grosspay [i] > 800)
			{
				taxrate [i] = 0.20;
			}			
			else if (grosspay [i] > 500)
			{
				taxrate[i] = 0.10;
			}
			
			if (ms[i] == 's' || ms[i] == 'S')
			{
				taxrate[i] = taxrate[i] + 0.05;
			}			
			else if (ms[i] == 'h' || ms[i] == 'H')
			{
				taxrate[i] = taxrate[i] - 0.05;
			}		
			
			taxamount[i] = grosspay[i] * taxrate[i];
			netpay[i] = grosspay[i] - taxamount[i];
			cout<< setw(7)<< firstname[i] << setw(14)<< lastname[i]<< setw(14)<< employeeid[i]<< setw(7)<< ms[i] <<setw(14)<< hoursworked[i] <<setw(14)<<grosspay[i]<<setw(14)<<netpay[i]<<setw(14)<<taxamount[i]<<endl;
			++i;
	}
		
	cout << "\n";								 //Creates 	space
	input.close(); //Closes the open file
	//system("pause");
	return 0;
}


Output:
FIRST NAME     LAST NAME   EMPLOYEE ID   STAT  HOURS WORKED     GROSS PAY     NET PAY         TAX

   John           Doe          1404      H            45           950         807.5         142.5
  Bobby          Jill          1404      S            45           950         712.5         237.5

Thanks, I am going to look at your first post and the corrections you pointed out, WOW the second post is so much simple, but I am supposed to be using loops, I think the objective is to learn how to use loops right now not to be efficient.
Topic archived. No new replies allowed.