Question: How to assign a cString to a structure variable only IF a condition is true C++? I have a program reading in employee information from

How to assign a cString to a structure variable only IF a condition is true C++?

I have a program reading in employee information from a text file and storing it into a structure. I also have an enum with F representing full-time employee and P representing part-time employee. If the employee is full-time, I deduct $5 from their pay for union dues. The text file is as follows

John 9.00 46.5 F Molly 9.50 40.0 F Tim 11.25 43.0 F Keil 6.50 35.0 P Trish 7.52 40.0 P Anthony 9.50 56.5 F Kevin 4.50 30.0 P Cheryl 4.65 45.0 F Kim 10.00 52.75 F Dave 5.75 48.0 F Will 15.00 45.25 P

Here is my structure and enum:

 enum EmpType{ F, P }; struct EmpData{ char* name; float payrate; float hours; EmpType employee_type; double pay; char deductions[]; };

I need to print out "Union dues deducted" if $5 has been deducted from the employee's pay. I assume I need some sort of if statement that prints it out if dues are deducted and doesn't do anything when fees haven't been deducted. and this is what I have so far. I've tried assigning deductions to a pointer and changing the types but I just can't wrap my head around what to do. When I try to assign "Union dues deducted" to employee deductions it says "expression must be a modifiable value".

void calculatePay(EmpData* employee[], int entries) { employee[entries]->pay = employee[entries]->payrate * employee[entries]->hours; // calculating pay if (employee[entries]->employee_type == F) { employee[entries]->pay = employee[entries]->pay - 5; } if (employee[entries]->pay == employee[entries]->pay - 5) { employee[entries]->deductions = "Union dues deducted"; // code goes here? } }

Output:

NAME RATE HOURS T PAY DEDUCTIONS ------- ----- ----- - ------ ------------------- John 9.00 46.50 F 413.50 Union dues deducted Molly 9.50 40.00 F 375.00 Union dues deducted Tim 11.25 43.00 F 478.75 Union dues deducted Keil 6.50 35.00 P 227.50 Trish 7.52 40.00 P 300.80 Anthony 9.50 56.50 F 531.75 Union dues deducted Kevin 4.50 30.00 P 135.00 Cheryl 4.65 45.00 F 204.25 Union dues deducted Kim 10.00 52.75 F 522.50 Union dues deducted Dave 5.75 48.00 F 271.00 Union dues deducted Will 15.00 45.25 P 678.75 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!