【发布时间】:2020-11-19 12:27:48
【问题描述】:
我目前正在为学生的分数制作一个索引器,但是,由于我是 C 新手,所以我不了解阅读错误。这是我遇到的错误:
- c:11:27: 错误:在“.”标记之前需要“;”、“,”或“)” 11 |双重平均(浮点输入.score,int input.many){
- c:34:13:警告:指针和整数之间的比较 34 | for(i=0; i many; i++){
- c:48:3:警告:函数“平均”的隐式声明 [-Wimplicit-function-declaration] 48 |平均(总和,nas->许多);
- while 循环无法正常工作
这是我正在处理的代码:
#include <stdio.h>
#include <string.h>
#define MAX 100
typedef struct{
float score, avg, sum, *many;
char name[100][100];
} input;
double average(float input.score, int input.many){
float sum=0, average, a;
int i;
for(i=0; i<input.many;i++){
sum += input[i].score;
}
a = sum/input.many;
average=a;
return average;
}
int main(){
input nas[MAX];
float sum;
int choose, i, aa;
printf("How many students do you want to input?\n");
scanf(" %d",&nas->many);
for(i=0; i < nas->many; i++){
input nas[i];
printf("\nName of Student-%d\t\t: ",i+1);
scanf(" %[^\n]s", nas[i].name);
printf("The score of Student-%d\t\t: ",i+1);
scanf(" %f", &nas[i].score);
while(nas[i].score > 100 && nas[i].score < 0){
printf("Invalid! Please re-input the score\t\t: ");
scanf(" %f",&nas[i].score);
}
average(sum, nas->many);
}
printf("1--> Average of the scores");
scanf("%d", &choose);
if(choose == 1){
printf("The average of %d students is %f", nas->many, average());
}
...
else{ return 0;}
谁能帮我理解它?非常感谢
【问题讨论】:
-
1.您不能在函数参数声明中使用
.。 2.i<input.many正在比较int和float*。这看起来很奇怪。您可能必须使用变量来存储数组的长度。 3.average的定义因为 1 无效。 4. 循环不会工作,因为你的代码不会编译。 -
@SZise 你好,我花了一点时间编辑你的代码并尝试理解它,你有很多错误,我已经做到了!您可以在下面查看
-
@MikeCAT 所以,对于数字 2,我需要声明另一个变量来存储数组?