C語言錯誤程式請大佬幫忙修改 原始碼
阿新 • • 發佈:2018-12-22
**
題目
**
定義序號、學號、姓名、獲得學分、高等數學、大學體育、中國近代史綱要、軟體技術導論、大學英語、C語言程式設計、平均分的資料型別,並輸入全班同學資料,根據成績計算獲得學分和平均分呢,並按照上表所示格式輸出(注意間隔和對齊)。在輸入過程中應該對成績的合法性、學號的規範性等進行判斷,以防止非法資料的流入。
圖片形式:
目前我已經完成了大部分內容,剩餘部分還未完成,但是現在我的程式已經出現了錯誤無法解決,請求大佬幫忙修改一下。
#include <stdio.h>
#include <string.h>
#define ST_NUM 35//學生數
typedef struct
{
char name[ST_NUM];
char id[ST_NUM];
int credit,math,pe,history,introduce,english,clangue,sum;
float average;
}student;
student ST[ST_NUM];
int main(int argc, char *argv[])
{
int i,j;
printf ("請輸入%d個學生的資訊:\n",ST_NUM);
for (i=0;i<ST_NUM;i++)
{
printf("序號 學號 姓名 數學成績 體育成績 歷史成績 導論成績 英語成績 C語言成績" );
scanf("%d %s %s %f %d %d %d %d %d %d %f",i,&ST[i].id,&ST[i].name,&ST[i].math,&ST[i].pe,&ST[i].history,&ST[i].introduce,&ST[i].english,&ST[i].clangue);
}
for(i=0;i<ST_NUM;i++)
{
&ST[i].sum=&ST[i].math+&ST[i].pe+&ST[i].history+&ST [i].introduce+&ST[i].english+&ST[i].clangue;//error C2110: cannot add two pointers
&ST[i].average=&ST[i].sum/6;//error C2296: '/' : illegal, left operand has type 'float *'
//這兩處錯誤如何修改?
}
student tstu;
//A1
for(i=0;i<ST_NUM;i++)
{
for(j=ST_NUM-1;j>i;j--)
{
if(ST[j].sum>ST[j-1].sum)
{
tstu=ST[j]; ST[j]=ST[i]; ST[i]=tstu;
}
}
}
//A1 這一部分的作用是什麼?
printf("┏━━┳━━━━━┳━━━━┳━━━┳━━━━┳━━━━┳━━━━┳━━━━┳━━━━┳━━━━┳━━━━┓\n");
printf("┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃\n");
printf("┃ 序 ┃ 學 ┃ 姓 ┃ 獲得 ┃ 高等數 ┃ 大學體 ┃中國近現┃ 軟體技 ┃ 大學英 ┃ C語言程┃ 平均 ┃\n");
printf("┃ 號 ┃ 號 ┃ 名 ┃ 學分 ┃ 學A1/5 ┃ 育1/1 ┃代史綱要┃術導論/2┃ 語A1/4 ┃ 序設計 ┃ 分 ┃\n");
printf("┃ ┃ ┃ ┃ ┃ ┃ ┃ /2 ┃ ┃ ┃ A/4 ┃ ┃\n");
printf("┣━━╋━━━━━╋━━━━╋━━━╋━━━━╋━━━━╋━━━━╋━━━━╋━━━━╋━━━━╋━━━━┫\n");
for (i=0;i<ST_NUM;i++)
{
printf("┃%4d┃%10s┃%8s┃%6d┃%8d┃%8d┃%8d┃%8d┃%8d┃%8d┃%8f┃\n",i,&ST[i].id,&ST[i].name,&ST[i].credit,&ST[i].math,&ST[i].pe,&ST[i].history,&ST[i].introduce,&ST[i].english,&ST[i].clangue,&ST[i].average);
printf("┣━━╋━━━━━╋━━━━╋━━━╋━━━━╋━━━━╋━━━━╋━━━━╋━━━━╋━━━━╋━━━━┫\n");
}
printf("┗━━┻━━━━━┻━━━━┻━━━┻━━━━┻━━━━┻━━━━┻━━━━┻━━━━┻━━━━┻━━━━┛\n");
return 0;
}//warning C4508: 'main' : function should return a value; 'void' return type assumed
程式碼截圖