What i am supposed to achieved is calculated the pay for all employees, however, in my code, all the dataElement in the link list becomes the same , as the last elementCode:void calAllPay(struct PersonalData* user){ struct PersonalData* currentEmp = user; int rate = 0; struct CompData* calculatedData; calculatedData = malloc(sizeof(struct CompData)); while(currentEmp!=NULL){ calculatedData->otPay = 0; calculatedData->weeklyPay = 0; if (currentEmp->hours > 40){ calculatedData->otHours = currentEmp->hours - 40; switch(currentEmp->jobCat){ case 'a': case 'A': rate = 10; break; case 'b': case 'B': rate = 15; break; case 'c': case 'C': rate = 20; break; } if (calculatedData->otHours <= 5){ calculatedData->otPay += (rate * 1.5); } else if ((calculatedData->otHours > 5) && (calculatedData->otHours <= 10)){ calculatedData->otPay += (rate * 1.5); calculatedData->otPay += (rate * 1.65); } else if ((calculatedData->otHours > 10) && (calculatedData->otHours <= 15)){ calculatedData->otPay += (rate * 1.5); calculatedData->otPay += (rate * 1.65); calculatedData->otPay += (rate * 1.75); } else if (calculatedData->otHours > 15){ calculatedData->otPay += (rate * 1.5); calculatedData->otPay += (rate * 1.65); calculatedData->otPay += (rate * 1.75); calculatedData->otPay += (rate * 1.6); } calculatedData->weeklyPay = currentEmp->basicPay + calculatedData->otPay; } else { calculatedData->otHours = 0; calculatedData->otPay = 0.00; calculatedData->weeklyPay = currentEmp->basicPay; } currentEmp->dataElement = calculatedData; currentEmp = currentEmp->nextElement; } &*user = currentEmp; printf("Pay successfully computed\n"); }
How can i stop it from overwriting