gpt4 book ai didi

c - 使用函数和 for 循环的 float 组

转载 作者:行者123 更新时间:2023-11-30 15:03:45 26 4
gpt4 key购买 nike

我只掌握了 C 语言的函数,所以请耐心等待。我的前两个函数是正确的,第三个函数可能是正确的。目标是在输入授予的分数和可用分数时能够输出最多 100 个作业的成绩。

我们得到的标准格式为 char GradeFromTotalRawMarks(floatmarksAwarded[], floatmarksAvailable[], int maxAssignments); 。我不断收到以下有关指针的错误(我还不知道),并且我不知道如何使用最大赋值,这应该指示传递给函数的赋值总数。

argument of type "float" is incompatible with parameter of type "float *" 'function':
cannot convert from 'float' to 'float *

代码如下:

#include <stdio.h>

char GradeFromPercentage(float percentage);
char GradeFromRawMarks(float marksAwarded, float marksAvailable);
char GradeFromTotalRawMarks(float marksAwarded[], float marksAvailable[], int maxAssignments);

int main()
{
int maxAssignments;
float MarksAwarded[100];
float MarksAvailable[100];
GradeFromTotalRawMarks(MarksAwarded[100], MarksAvailable[100], maxAssignments);

return 0;
}
char GradeFromPercentage(float percentage)
{
char grade;
if (percentage >= 90)
{
grade = 'A';
}
else if (percentage >= 70)
{
grade = 'B';
}
else if (percentage >= 50)
{
grade = 'C';
}
else if (percentage >= 30)
{
grade = 'D';
}
else
{
grade = 'F';
}
return grade;
}

char GradeFromRawMarks(float marksAwarded, float marksAvailable)
{
float percentage = (marksAwarded / marksAvailable) * 100;
GradeFromPercentage(percentage);

return GradeFromPercentage(percentage);
}
char GradeFromTotalRawMarks(float marksAwarded[], float marksAvailable[], int maxAssignments)
{
char finish = 'n';
int count1;
while (finish == 'n')
{
for (count1 = 0; count1 < 100 && finish == 'n'; count1++)
{
printf("Enter the marks awarded:");
scanf("%f", &marksAwarded[count1]);
printf("Enter the marks available: \n", &marksAvailable[count1]);
scanf("%f", &marksAvailable[count1]);

GradeFromRawMarks(marksAwarded[count1], marksAvailable[count1]);

printf("If you have finished, type n.");
scanf("%c", &finish);
}
}

return GradeFromRawMarks(marksAwarded[count1], marksAvailable[count1]);
}

最佳答案

在你的主函数中,检查这一行:

GradeFromTotalRawMarks(MarksAwarded[100], MarksAvailable[100], maxAssignments);

第一个参数错误。您应该传递整个数组。将该行更改为:

GradeFromTotalRawMarks(MarksAwarded, MarksAvailable, maxAssignments);

修复上述问题后,我编译了您的代码,它编译时没有任何错误。

关于c - 使用函数和 for 循环的 float 组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40579416/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com