Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Best way to do this

Name: Alex 2011-11-24 18:12

Hey /g/. I'm doing an assignment and it asks me to read in a bunch of integers from a text file into an array (marks for assignments). I have an array[10][4], 10 students with 4 grades each.

What I want to do is check the value of these grades, and if they're say <=40, then do something, if they're >70, do something. I need to count up the number of marks in each bracket. I could easily do this using for loops in the main function, but it seems very messy and we're marked on the way we implement the program rather than simply solving the problem.

I tried to use the array as a parameter to a function, and then use the function to check the values, but I couldn't get this to work. Could I use pointers to do this? Jus tell me the best way to do it /g/, I can try to implement it myself. The language is C, by the way.

Name: F r o z e n V o i d !!mJCwdV5J0Xy2A21 2011-11-25 11:09

#include <fcntl.h>
#include <stdio.h>
#define STGRADES 10*4
main(int argc, char** argv){
int low = 0,med =0,high=0,i=-1,grades[STGRADES];
read(open(argv[1],O_RDONLY),&grades,STGRADES<<2);
while(++i<STGRADES)grades[i]<41?++low:(grades[i]>70?++high:++med);
printf("There were: %d low grades, %d average grades, and %d high grades\n", low, med, high);}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List