#include <stdio.h>
#define N 20
typedef struct {
int b; /*学生番号*/
int t; /*体重*/
}Student;
int print_dt(Student *p);
int main( ){
Student stu[N+1];
int i = 0;
int s = 0;
printf("学生番号、体重を入力(終了条件:Ctrl+Z)\n");
while( (scanf("%d %d",&stu[i].b,&stu[i].t)!=EOF) && i<N){
i++;
s += stu[i].t;
}
stu[i].b = 0;
stu[i].t = 0;
print_dt(stu);
printf("学生の体重合計は%dです\n",s);
return 0;
}
int print_dt(Student *p){
printf("学生番号 体重\n");
while(p->b!=0 && p->t!=0){
printf("%8d%12d\n",p->b,p->t);
p++;
}
return 0;
}
インクリメントの位置が間違ってましたっ で。OKです♪
#include <stdio.h>
#define N 20
typedef struct {
int b; /*学生番号*/
int t; /*体重*/
}Student;
int print_dt(Student *p);
int main( ){
Student stu[N+1];
int i = 0;
int s = 0;
printf("学生番号、体重を入力(終了条件:Ctrl+Z)\n");
while( (scanf("%d %d",&stu[i].b,&stu[i].t)!=EOF) && i<N){
s += stu[i].t;
i++;
}
stu[i].b = 0;
stu[i].t = 0;
print_dt(stu);
printf("学生の体重合計は%dです\n",s);
return 0;
}
int print_dt(Student *p){
printf("学生番号 身長\n");
while(p->b!=0 && p->t!=0){
printf("%8d%12d\n",p->b,p->t);
p++;
}
return 0;
}
|
かぎ//今見直してエラーがわかりました!!「i++;」の位置がダメだったんです。。。かぎさんのプログラムも参考にさせてもらいますね!ありがとうございます☆
2008/5/19(月) 午前 0:16