这个C语言程序为什么运行部了,问题出在哪里啦?
我是用VS2017编译的#include <stdio.h>
#include <iostream>
#include <windows.h>
using namespace std;
struct student {
int num;
char name;
int computer, english, math;
double average;
};
int main(int argc, char* argv[]) {
system("color 0b");
int i, n;
struct student max, s1;
printf("Input n");
scanf_s("%d", &n);
for (i = 1; i <= n; i++) {
printf("No.%d", i);
scanf_s("%d %s %d %d %d", &s1.num, &s1.name, &s1.computer, &s1.english, &s1.math);
s1.average = (s1.math + s1.computer + s1.english) / 3.0;
if (i == 1) {
max = s1;
}
if (max.average < s1.average) {
max = s1;
}
}
printf("num:%d,name:%s,average:%f\n", max.num, max.name, max.average);
system("pause");
}
你头文件用的C++,不是C额 报什么错
因为你的一个s1无法接收n个student的信息,每次输入信息都会覆盖掉,你可以定义一个student类型的数组s[]并且保证数组容量大于等于n
页:
[1]