Payroll Program w/Array - Marital Status Always M?

Hello. I'm very new, in my first programming class with no experience. I'm working on a payroll program using arrays, but the "marital status" part is giving me trouble. No matter what I input in the program, it always displays marital status as "M" or whichever item I put first in the code.

I've posted the entire code because I'm not sure where the problem is.

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
#include<iostream>
#include<iomanip>
using namespace std;

main(){
	char empid[100][12];
	char fname[100][10], lastname[100][15], maritalstatus[100];
	int hw[100];
	double gp[100], np[100], hr[100], taxrate[100], taxamt[100];
	int counter = 0;
	int i;
	cout<<"ENTER EMPLOYEE ID, FIRST NAME, LAST NAME, MARITAL STATUS, HOURS WORKED, HOURLY RATE"<<endl;
while(cin>>empid[counter]>>fname[counter]>>lastname[counter]>>maritalstatus[counter]>>hw[counter]>>hr[counter]){
	counter=counter+1;
	for (i=0; i<counter; i++){
		gp[i] = hw[i] * hr [i];
	} //end grosspay for loop
	for (i=0;i<counter;i++){
		if(gp[i]>500) taxrate[i] = .30;
		else if (gp[i]>200) taxrate[i] = .20;
	else taxrate[i] = .10;
	}
	for (i=0; i<counter; i++){
		if (maritalstatus[i]= 'M', 'm')	taxrate[i] +=0.0;
        else if(maritalstatus[i]='S', 's') taxrate[i]=taxrate[i]+.05;
		else if (maritalstatus[i] = 'H', 'h') if (taxrate[i]>0.05) taxrate[i] -=.05;
	}
	for (i=0; i<counter; i++){
		taxamt[i] = gp[i] * taxrate[i];
	}
	for (i=0; i<counter; i++){
		np[i] = gp [i] - taxamt [i];
	}
	cout<<endl;
	cout<<setw(14)<<"ID"<<setw(11)<<"FN"<<setw(16)<<"LN"<<setw(2)<<"MS"<<setw(4)<<"HW"
	<<setw(5)<<"HR"<<setw(6)<<"GROSS"<<setw(6)<<"TAX"<<setw(9)<<"NET"<<endl<<endl;
for (i=0; i<counter; i++){
	setprecision(2); setiosflags(ios::fixed|ios::showpoint|ios::left);
	cout<<setw(14)<<empid[i]<<setw(11)<<fname[i]<<setw(16)<<lastname[i]<<setw(2)<<maritalstatus[i]<<setw(4)<<hw[i]
	<<setw(5)<<hr[i]<<setw(6)<<gp[i]<<setw(6)<<taxamt[i]<<setw(9)<<np[i]<<endl;
}//FOR
}
return 0;
}//MAIN 
it is int main() not main() as far as your problem look at line 24 and 26. You are setting them equal to not comparing. Use the == operator to compare. Also it shouldn't even compile like that. You have to check each one you cant do if it is equal to this or that....it should be
if( maritalstatus[ i ] == 'M' || maritalstatus[ i ] == 'm' ).....

Also might I suggest using a struct for your employees?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
struct Employee
{
    std::string first , last;
    char marital;
    int ID , hours , wage;
};

int main()
{
    Employee Fred = { "Fred" , "Something" , 'M' , 1234 , 40 , 8.50 } , bob;
    std::string temp_str;
    char temp_ch;
    int temp_in;
    std::cout << "First name: " << std::flush;
    std::cin >> bob.first;
    /*...*/
}
Not to throw in more complexity, but depending on if the output has to be a format of S/M/W/etc you could throw in a switch statement to print out Single, Married, Widow, etc.
Topic archived. No new replies allowed.