#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void calculate(float *payperhour, float *hoursworked, float *wage, float *overtime,int p)
{
if (&hoursworked[p] > 40)
    overtime[p] = ((hoursworked[p] - 40) * payperhour[p] * 1.5);
    wage[p] = overtime[p] + (payperhour[p] * 40);
if (hoursworked[p] <= 40)
    overtime[p] = 0;
    wage[p] = hoursworked[p] * payperhour[p];
}



void main(void)
{
int i = 0;
char employee[5][10];
float payperhour[10];
float hoursworked[10];
float wage[10];
float overtime[10];
int p = 0;
// establish the variables needed to run the formulas for pay




for (i = 0; i <= 4; i)
{
    printf("Give me an Employees name.\n");
    scanf_s(" %[^\n]s %d", &employee[i], 10);
    if (strcmp(employee[i], "-1") == 0)
        break;
    printf("What is this Employees wage per hour?\n");
    scanf_s("%f", &payperhour[i]);
    if (payperhour[i] == -1)
        break;
    printf("How many hours did this employee work?\n");
    scanf_s("%f", &hoursworked[i]);
    if (hoursworked[i] == -1)
        break;
    i++;
}
//for loop that assigns all the variables needed to figure out pay
for (p = 0; p <= 4; p)
{
    calculate(&payperhour[p], &hoursworked[p], &wage[p], &overtime[p], p);
    p++;
}
//actualy equation that computes all the pay that everyone is receiving
for (p = 0; p < i; p)
{
    printf("Employee %s:\n", employee[p]);
    printf("Pay per hour:\n %.2f\n", payperhour[p]);
    printf("Hours Worked:\n %.2f\n", hoursworked[p]);
    printf("Gross Pay:\n %.2f\n", wage[p]);
    printf("Overtime pay:\n %.2f\n", overtime[p]);
    printf("Pay after taxes:\n %.2f\n", wage[p] * .8);
    p++;
    //finishes the application by giving the user the information that was computed
}
system("pause");
}

这是我的代码,我目前正在接受C编程,并已陷入这个问题。当您将用户输入数组spot 0(在所有数组上)时,它工作正常。但如果你把信息输入到第1或第3点,它就不能为这些信息提供适当的工资或加班费。我不明白为什么它会在偶数数组上工作,但在偶数数组上不工作。
[1]的工资和加班费总是以百万计,但[0]的工资和加班费工作正常
我知道这段代码甚至还不够完美,但我正在试图解决这个问题,而且在我的一生中,我无法找出任何关于我遇到的问题的信息。
我已经编辑了包括整个代码,因为它是要求的

最佳答案

您将&payperhour[p]作为payperhour传递,然后使用payperhour[p]
注意(&payperhour[p])[p]payperhour[p+p]payperhour[p*2]相同。
您似乎想这样调用函数:

calculate(payperhour, hoursworked, wage, overtime, p);

09-04 17:58
查看更多