我已经没有办法了,也就是说我对自己的困惑感到困惑我的CS36班作业。
我们应该在C语言中创建一个简单的工资单程序,其中我们使用一种方法输入5个不同的员工姓名、工作时间和小时工资率在该方法中,我们应该使用参数传递和按引用传递然后用另一种方法计算总工资、基本工资和加班费,通过引用传递然后使用另一种计算税款的方法,将工资总额作为输入,返回所欠税款然后我们打印所有5个的细节。
我甚至在第一部分也有问题当我在main中输入name&hours时,我相信没有什么问题然而,当我把这些输入放在我在main中调用的函数中时,exe在我输入名称之后就挂起了。
我已经读了将近3个小时的函数、参数和通过引用传递的内容,但我仍然很困惑很有可能是我得不到的一旦我跨过那座桥,我将克服其他功能的障碍。

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#define size 5

void inputNameRateHours(char name, double rate, double hours);
double computeGross(double hoursworked, double hourlyrate);
//double computeOvertime(double hoursworked, double overtimerate)
//double computeTax(double gross);
//double computeNet(double gross, double tax);
//double totalpaidtoallemployees(double gross[size]);
//void printmethod(double *totalpaidtoallemployees);

int main()
{
    char name=0;
    double hours = 0, rate = 0,  gross = 0, tax = .2, totalpaidtoallemployees = 0;
    inputNameRateHours(name, rate, hours);
    printf("The name %s, the rate %d, the hours%f", &name, &rate, &hours);
    gross= computeGross(hours, rate);
    printf("");
    //computeTax(gross);
    //computeNet(gross, tax);
    //totalpaidtoallemployees*(gross);


    return 0;

}
void inputNameRateHours(char *name, double *rate, double *hours) {
    int loopcount;
    for (loopcount = 0; loopcount < size; loopcount++)
    {
        printf("Employee Name:");
        scanf("\n %s \n", &name);
        if (strcmp(name, "-1") == 0)
            break;
        printf("\n Enter hourly rate:");
        scanf("%d", &rate);
        if ((rate = -1) == 0)
            break;
        printf("\n Enter hours worked:");
        scanf("%d", &hours);
        if ((hours = -1) == 0)
            break;
    }
}
double computeGross(double hours, double rate) {
    if (hours <= 40)
        return hours*rate;
    else if (hours > 40)
        printf("This employee worked overtime.");
}

最佳答案

对于inputNameRateHours(...),main之前给出的原型和main之后实现的函数头是不同的。
原型前用直接参数,实现后用指针指向参数。
我建议编译时使用严格的警告,例如gcc -Wall
据我所知,你必须解决:
上述原型错误
缺少include
名称空间
改进扫描
第二个函数中缺少返回
间接寻址/解引用不匹配的几种情况(&/*
作业内部比较
浮点恒等式比较
printf中的格式说明符
你表示你已经满足了,所以我就不谈了;
与StackOverflow推荐的家庭作业/作业相匹配。
祝你好运。

关于c - C名称和2个 double 的函数,循环5次并通过引用传递,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45252836/

10-11 22:59
查看更多