Created
August 15, 2017 12:22
-
-
Save sthoshi/73596c6905b7265bd699c2ba844cd50a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#define N 100 | |
int gradeABCD(int); | |
int main(){ | |
int point[N],i,j,grade[N],SumPoints,cal; | |
double unit[N],SumUnits,GPAPoints; | |
SumPoints=0; | |
SumUnits=0; | |
printf("科目の点数、単位数をそれぞれ空白を空けて入力してください。\n0~49:D,50~64:C,65~79:B,80~100:A\nマイナスの値が入力された場合入力を終了します。\n"); | |
for(i=0;i<N;i++){ | |
scanf("%d",&point[i]); | |
if(point[i]<0){ | |
break; | |
} | |
grade[i]=gradeABCD(point[i]); //A=4,B=3,C=2,D=0と判定し、返す | |
scanf("%lf",&unit[i]); | |
} | |
for(j=0;j<i;j++){ | |
SumPoints+=grade[j]*unit[j]; | |
SumUnits+=unit[j]; | |
} | |
GPAPoints=SumPoints/SumUnits; | |
printf("あなたのGPAは%.3fです。\n",GPAPoints); | |
return 0; | |
} | |
int gradeABCD(int x){ | |
if(x>=80) return 4; | |
else if(x>=65) return 3; | |
else if(x>=50) return 2; | |
else return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment