至急!教えてください。
#include <stdio.h>
#include <windows.h>
#define COUNT (3)
struct Seiseki{
char name[20];
int score1;
int score2;
int score3;
int score4;
int score5;
int average;
};
int getValue(char str[], char temp[], int n){
memset(temp, 0, 19);
while(*(str+n) == ' '){
n++;
}
int i = 0;
while(*(str+n) != ' ' && *(str+n) != 0){
temp[i] = *(str+n);
i++;
n++;
}
return n;
}
void getAverage(Seiseki *seiseki){
int total = seiseki->score1 +
seiseki->score2 +
seiseki->score3 +
seiseki->score4 +
seiseki->score5;
seiseki->average = total / 5;
}
void getSeiseki(Seiseki seiseki[]){
char temp[20];
char str[256];
for(int i = 0; i < COUNT; i++){
printf_s("%d 人目の点数と名前 > ", i+1);
memset(str, 0, 255);
gets(str);
int n = 0;
n = getValue(str, temp, n);
strcpy(seiseki[i].name, temp);
n = getValue(str, temp, n);
seiseki[i].score1 = atoi(temp);
n = getValue(str, temp, n);
seiseki[i].score2 = atoi(temp);
n = getValue(str, temp, n);
seiseki[i].score3 = atoi(temp);
n = getValue(str, temp, n);
seiseki[i].score4 = atoi(temp);
n = getValue(str, temp, n);
seiseki[i].score5 = atoi(temp);
getAverage(&seiseki[i]);
}
}
void showSeiseki(Seiseki seiseki[]){
for(int i = 0; i < COUNT; i++){
printf("%d %s %d %d %d %d %d\n", i+1,
seiseki[i].name,
seiseki[i].score1,
seiseki[i].score2,
seiseki[i].score3,
seiseki[i].score4,
seiseki[i].score5,
seiseki[i].average);
}
}
void showScoresAverage(Seiseki seiseki[]){
int total1 = 0;
int total2 = 0;
int total3 = 0;
int total4 = 0;
int total5 = 0;
for(int i = 0; i < COUNT; i++){
total1+=seiseki[i].score1;
total2+=seiseki[i].score2;
total3+=seiseki[i].score3;
total4+=seiseki[i].score4;
total5+=seiseki[i].score5;
}
int ave1 = total1 / COUNT;
int ave2 = total2 / COUNT;
int ave3 = total3 / COUNT;
int ave4 = total4 / COUNT;
int ave5 = total5 / COUNT;
printf_s("\naverage %d %d %d %d %d\n",ave1,
ave2,
ave3,
ave4,
ave5);
}
void main(){
Seiseki seiseki[COUNT];
printf_s("生徒 %d 名分の成績を入力してください:\n", COUNT);
getSeiseki(seiseki);
printf_s("\n成績表\n# NAME #1 #2 #3 #4 #5 average\n");
showSeiseki(seiseki);
showScoresAverage(seiseki);
}
間違っている点がありますか?
ありましたらどこに入れるか教えてください。
改良点などありましたらお願いします。
お礼
ありがとうございました。