1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
#include <stdio.h>
/* no. repeat NO
#define p ;printf
#define s ;scanf */
main()
{
/* use comments to state only those things that can't be expressed in code
int a,b,c,d,w,x,y,z, total_score=0, quotient //a,w = Written exam, b,x = Lab drill, c,y = Final Lab, d,z = Final Written Exam
*/
puts( "FINAL GRADE COMPUTATION" );
puts( "Please input raw and maximum scores of Written Exam separated by '/'" );
int written_exam_score, written_exam_max ; // use variable names that convey meaning
if( scanf( "%d / %d", &written_exam_score, &written_exam_max ) < 2 )
{
puts( "input failed" ) ;
return 1 ;
}
if( written_exam_score < 0 || written_exam_max < written_exam_score )
{
puts( "invalid Written Exam score" ) ;
return 1 ;
}
printf( "Your Written Exam score is %.2f percent\n", written_exam_score * 100.0 / written_exam_max );
puts( "Please input raw and maximum scores of Lab drill separated by '/'" );
int lab_drill_score, lab_drill_max ;
if( scanf( "%d / %d", &lab_drill_score, &lab_drill_max ) < 2 )
{
puts( "input failed" ) ;
return 1 ;
}
if( lab_drill_score < 0 || lab_drill_max < lab_drill_score )
{
puts( "invalid Lab drill score" ) ;
return 1 ;
}
printf( "Your Lab Drill score is %.2f percent\n", lab_drill_score * 100.0 / lab_drill_max );
puts( "Please input raw and maximum scores of Lab final separated by '/'" );
int lab_final_score, lab_final_max ;
if( scanf( "%d / %d", &lab_final_score, &lab_final_max ) < 2 )
{
puts( "input failed" ) ;
return 1 ;
}
if( lab_final_score < 0 || lab_final_max < lab_final_score )
{
puts( "invalid Lab final score" ) ;
return 1 ;
}
printf( "Your Lab final score is %.2f percent\n", lab_final_score * 100.0 / lab_final_max );
puts( "Please input raw and maximum scores of Final exam separated by '/'" );
int final_exam_score, final_exam_max ;
if( scanf( "%d / %d", &final_exam_score, &final_exam_max ) < 2 )
{
puts( "input failed" ) ;
return 1 ;
}
if( final_exam_score < 0 || final_exam_max < final_exam_score )
{
puts( "invalid Final exam score" ) ;
return 1 ;
}
printf( "Your Final exam score is %.2f percent\n", final_exam_score * 100.0 / final_exam_max );
const int total_score = written_exam_score + lab_drill_score + lab_final_score + final_exam_score ;
const int total_max = written_exam_max + lab_drill_max + lab_final_max + final_exam_max ;
const double percentage = total_score * 100.0 / total_max ;
printf( "\nyour overall score is %u / %u or %.2f %%\n", total_score, total_max, percentage ) ;
}
|