ผมอยากได้แบบนี้คับ เป็นโปรเจกส่งอาจารย์ปลายเทอม
ID Name Score1 Score2 Score3 Score Grade
.
.
.
แต่ผมไม่รู้ว่าจะให้มันรับ Name แล้วแสดง Name ที่เป็นอักขระยังไง
ผมเขียนได้แค่
ID Score1 Score2 Score3 Score Grade
.
.
.
.
#include<stdio.h>
#include<conio.h>
#include<math.h>
//function
void grade(int count,int id[],int sc1[],int sc2[],int sc3[],int score[]);
void grade2(int count,int id[],int sc1[],int sc2[],int sc3[],int score[]);
main(){
int j,count;
//pass word
do{
printf("Please Enter Password:");
scanf("%d",&j);
}while(j!=999999);
char sub[999],fac[999],ye[4],ma[999];
//input data
printf("Enter Subject:");
scanf("%s",&sub);
printf("Enter Faculty:");
scanf("%s",&fac);
printf("Enter Year:");
scanf("%s",&ye);
printf("Enter Major:");
scanf("%s",ma);
printf("Enter Number of Students:");
scanf("%d",&count);
//loop number of student
int id[count],sc1[count],sc2[count],sc3[count],score[count],i=0;
while(i<count){
printf("Enter ID:");
scanf("%d",&id);
printf("Enter Score1:");
scanf("%d",&sc1);
printf("Enter Score2:");
scanf("%d",&sc2);
printf("Enter Score3:");
scanf("%d",&sc3);
score=sc1+sc2+sc3;
i++;
}
printf("\n");
//choose form for grading
int sel;
printf("1.Grade Standard\t2.Grade Rank\n");
do{
scanf("%d",&sel);
printf("\n");
}while(sel!=1 && sel!=2);
printf("=============================================\n");
printf("Subject: %s\n",sub);
printf("Faculty: %s\n",fac);
printf("Year: %s\n",ye);
printf("Major: %s\n",ma);
printf("Number of student: %d\n",count);
printf("=============================================\n");
if(sel==1){
grade(count,id,sc1,sc2,sc3,score);
}else if(sel==2){
grade2(count,id,sc1,sc2,sc3,score);
}
//compute and show mean and S.D.
float x,sd,sum1=0,sum2=0;
//compute mean
for(i=0;i<count;i++){
sum1+=score;
}
x=sum1/count;
printf("Mean = %.2f\n",x);
//compute S.D.
for(i=0;i<count;i++){
sum2+=pow(score-x,2);
}
sd=sum2/(count-1);
printf("S.D. = %.2f\n",sqrt(sd));
printf("*************<< End Grading >>***************\n");
getch();
}
//my function
//function for grading rank
void grade2(int count,int id[],int sc1[],int sc2[],int sc3[],int score[]){
int i=0,rankA[2],rankB1[2],rankB[2],rankC1[2],rankC[2],rankD1[2],rankD[2],rankF[2];
printf("Enter Rank A:");
scanf("%d %d",&rankA[0],&rankA[1]);
printf("Enter Rank B+:");
scanf("%d %d",&rankB1[0],&rankB1[1]);
printf("Enter Rank B:");
scanf("%d %d",&rankB[0],&rankB[1]);
printf("Enter Rank C+:");
scanf("%d %d",&rankC1[0],&rankC1[1]);
printf("Enter Rank C:");
scanf("%d %d",&rankC[0],&rankC[1]);
printf("Enter Rank D+:");
scanf("%d %d",&rankD1[0],&rankD1[1]);
printf("Enter Rank D:");
scanf("%d %d",&rankD[0],&rankD[1]);
printf("Enter Rank F:");
scanf("%d %d",&rankF[0],&rankF[1]);
printf("=============================================\n");
printf(" ID Score1 Score2 Score3 Score Grade\n");
while(i<count){
printf("%3d %5d %8d %8d %7d ",id,sc1,sc2,sc3,score);
if(score>=rankA[0]&&score<=rankA[1]){
printf("A\n");
}else if(score>=rankB1[0]&&score<=rankB1[1]){
printf("B+\n");
}else if(score>=rankB[0]&&score<=rankB[1]){
printf("B\n");
}else if(score>=rankC1[0]&&score<=rankC1[1]){
printf("C+\n");
}else if(score>=rankC[0]&&score<=rankC[1]){
printf("C\n");
}else if(score>=rankD1[0]&&score<=rankD1[1]){
printf("D+\n");
}else if(score>=rankD[0]&&score<=rankD[1]){
printf("D\n");
}else if(score>=rankF[0]&&score<=rankF[1]){
printf("F\n");
}
i++;
}
printf("=============================================\n");
}
//function for grading standard
void grade(int count,int id[],int sc1[],int sc2[],int sc3[],int score[]){
int i=0;
printf(" ID Score1 Score2 Score3 Score Grade\n");
while(i<count){
printf("%3d %5d %8d %8d %6d ",id,sc1,sc2,sc3,score);
if(score>79){
printf("A\n");
}else if(score>74){
printf("B+\n");
}else if(score>69){
printf("B\n");
}else if(score>64){
printf("C+\n");
}else if(score>59){
printf("C\n");
}else if(score>54){
printf("D+\n");
}else if(score>49){
printf("D\n");
}else{
printf("F\n");
}
i++;
}
printf("=============================================\n");
}
ช่วยดูให้หน่อยคับ
ช่วยด้วยคับ รับค่า-แสดงค่า รายชื่อ ภาษา C
ID Name Score1 Score2 Score3 Score Grade
.
.
.
แต่ผมไม่รู้ว่าจะให้มันรับ Name แล้วแสดง Name ที่เป็นอักขระยังไง
ผมเขียนได้แค่
ID Score1 Score2 Score3 Score Grade
.
.
.
.
#include<stdio.h>
#include<conio.h>
#include<math.h>
//function
void grade(int count,int id[],int sc1[],int sc2[],int sc3[],int score[]);
void grade2(int count,int id[],int sc1[],int sc2[],int sc3[],int score[]);
main(){
int j,count;
//pass word
do{
printf("Please Enter Password:");
scanf("%d",&j);
}while(j!=999999);
char sub[999],fac[999],ye[4],ma[999];
//input data
printf("Enter Subject:");
scanf("%s",&sub);
printf("Enter Faculty:");
scanf("%s",&fac);
printf("Enter Year:");
scanf("%s",&ye);
printf("Enter Major:");
scanf("%s",ma);
printf("Enter Number of Students:");
scanf("%d",&count);
//loop number of student
int id[count],sc1[count],sc2[count],sc3[count],score[count],i=0;
while(i<count){
printf("Enter ID:");
scanf("%d",&id);
printf("Enter Score1:");
scanf("%d",&sc1);
printf("Enter Score2:");
scanf("%d",&sc2);
printf("Enter Score3:");
scanf("%d",&sc3);
score=sc1+sc2+sc3;
i++;
}
printf("\n");
//choose form for grading
int sel;
printf("1.Grade Standard\t2.Grade Rank\n");
do{
scanf("%d",&sel);
printf("\n");
}while(sel!=1 && sel!=2);
printf("=============================================\n");
printf("Subject: %s\n",sub);
printf("Faculty: %s\n",fac);
printf("Year: %s\n",ye);
printf("Major: %s\n",ma);
printf("Number of student: %d\n",count);
printf("=============================================\n");
if(sel==1){
grade(count,id,sc1,sc2,sc3,score);
}else if(sel==2){
grade2(count,id,sc1,sc2,sc3,score);
}
//compute and show mean and S.D.
float x,sd,sum1=0,sum2=0;
//compute mean
for(i=0;i<count;i++){
sum1+=score;
}
x=sum1/count;
printf("Mean = %.2f\n",x);
//compute S.D.
for(i=0;i<count;i++){
sum2+=pow(score-x,2);
}
sd=sum2/(count-1);
printf("S.D. = %.2f\n",sqrt(sd));
printf("*************<< End Grading >>***************\n");
getch();
}
//my function
//function for grading rank
void grade2(int count,int id[],int sc1[],int sc2[],int sc3[],int score[]){
int i=0,rankA[2],rankB1[2],rankB[2],rankC1[2],rankC[2],rankD1[2],rankD[2],rankF[2];
printf("Enter Rank A:");
scanf("%d %d",&rankA[0],&rankA[1]);
printf("Enter Rank B+:");
scanf("%d %d",&rankB1[0],&rankB1[1]);
printf("Enter Rank B:");
scanf("%d %d",&rankB[0],&rankB[1]);
printf("Enter Rank C+:");
scanf("%d %d",&rankC1[0],&rankC1[1]);
printf("Enter Rank C:");
scanf("%d %d",&rankC[0],&rankC[1]);
printf("Enter Rank D+:");
scanf("%d %d",&rankD1[0],&rankD1[1]);
printf("Enter Rank D:");
scanf("%d %d",&rankD[0],&rankD[1]);
printf("Enter Rank F:");
scanf("%d %d",&rankF[0],&rankF[1]);
printf("=============================================\n");
printf(" ID Score1 Score2 Score3 Score Grade\n");
while(i<count){
printf("%3d %5d %8d %8d %7d ",id,sc1,sc2,sc3,score);
if(score>=rankA[0]&&score<=rankA[1]){
printf("A\n");
}else if(score>=rankB1[0]&&score<=rankB1[1]){
printf("B+\n");
}else if(score>=rankB[0]&&score<=rankB[1]){
printf("B\n");
}else if(score>=rankC1[0]&&score<=rankC1[1]){
printf("C+\n");
}else if(score>=rankC[0]&&score<=rankC[1]){
printf("C\n");
}else if(score>=rankD1[0]&&score<=rankD1[1]){
printf("D+\n");
}else if(score>=rankD[0]&&score<=rankD[1]){
printf("D\n");
}else if(score>=rankF[0]&&score<=rankF[1]){
printf("F\n");
}
i++;
}
printf("=============================================\n");
}
//function for grading standard
void grade(int count,int id[],int sc1[],int sc2[],int sc3[],int score[]){
int i=0;
printf(" ID Score1 Score2 Score3 Score Grade\n");
while(i<count){
printf("%3d %5d %8d %8d %6d ",id,sc1,sc2,sc3,score);
if(score>79){
printf("A\n");
}else if(score>74){
printf("B+\n");
}else if(score>69){
printf("B\n");
}else if(score>64){
printf("C+\n");
}else if(score>59){
printf("C\n");
}else if(score>54){
printf("D+\n");
}else if(score>49){
printf("D\n");
}else{
printf("F\n");
}
i++;
}
printf("=============================================\n");
}
ช่วยดูให้หน่อยคับ