โจทย์มีว่า จงเขียนโปรแกรมหาคะแนนสูงสุดของนิสิตจำนวน 5 คนและแสดงรายชื่อนิสิตที่ได้คะแนนสูงสุดนั้น โดยโปรแกรมให้ผู้ใช้กรอกข้อมูล ชื่อ-นามสกุลและคะแนนของนิสิตทั้ง 5 คนและใช้ตัวแปรโครงสร้างเก็บข้อมูลของนิสิต
#include<stdio.h>
struct data{
char name[40];
char score;
};
main()
{
char name;
int i,max;
struct data student[5];
for(i=0; i<5; i++)
{
printf("\n student %d \n",i+1);
printf(" Enter Name >> "); gets(student.name);
printf(" Enter Score >> "); scanf("%d",&student.score);getchar();
}
for(i=0; i<5; i++)
{
student.name;
if(max<student.score)
max=student.score;
name=student.name;
}
printf("\n The maximum score name is %c",name);
printf("\n The maximum score is %d",max);
}
ตอนนี้ติดตรงไม่สามารถเอาชื่อมาขึ้นด้วยได้ครับTT
ช่วยคิดหน่อยครับไปต่อไม่เป็นแล้วภาษาซี
#include<stdio.h>
struct data{
char name[40];
char score;
};
main()
{
char name;
int i,max;
struct data student[5];
for(i=0; i<5; i++)
{
printf("\n student %d \n",i+1);
printf(" Enter Name >> "); gets(student.name);
printf(" Enter Score >> "); scanf("%d",&student.score);getchar();
}
for(i=0; i<5; i++)
{
student.name;
if(max<student.score)
max=student.score;
name=student.name;
}
printf("\n The maximum score name is %c",name);
printf("\n The maximum score is %d",max);
}
ตอนนี้ติดตรงไม่สามารถเอาชื่อมาขึ้นด้วยได้ครับTT