2_2.c |
| #include <stdio.h> #include <stdlib.h> main(){ int lowest,n,highest=0; double s1,s2,s3,temp,temp_hi=0,score; /* loops until scanf returns an error... hopefully that means the end of the file! */ while(scanf("%d%lg%lg%lg",&n,&s1,&s2,&s3)!=EOF){ /* the following works out score of the individual */ lowest=1; temp=s1; if(s2<temp){ lowest=2; temp=s2; } if(s3<temp) lowest=3; if(lowest==1) score=(s2+s3)/2; else if(lowest==2) score=(s1+s3)/2; else score=(s1+s2)/2; /* this works out whether this is the top score to date */ if(score>temp_hi){ temp_hi=score; highest=n; } } printf("The winner is cometitor number %d, with a score of %f\n", highest, temp_hi); return 0; } |
James Little |