competition program

You are to write a program that reads in competition results for asingle team from a file and calculates the final score for the team. The file name must be supplied by the user, and you must deal with incorrect file names appropriately. The input format and output formats are described below.
Input File Format. The input file will be of the following format:
² Row one of the file will have two integers: the number of problems and number of judges. You can assume that the number of problems will always be greater than zero and less than 10. You can assume that the number of judges will always be greater than two and less than 10.
² The next row in the file will be the di±culty rating for each of the problems.
² There will then be multiple rows giving results for the team for each problem. They will have the format:
problem number, time taken, score from judge 1, score from judge 2... etc.
Note that the team may not have attempted every problem.
For example:
3 6
2.1 1.9 1.8
2 10 6.0 2.1 6.5 7.0 8.0 7.5
1 30 2.3 7.0 7.0 7.0 7.0 7.0
3 15 1.9 5.0 6.5 7.0 7.0 5.5

could anyone give me clue how to start coding this program. I have to use arrays .
your kind help will be greatfull.

Zuk
Last edited on
Hi everyone,

I'm still waiting for any kind reply.
Step 1.
Read http://www.cplusplus.com/forum/beginner/1/
Step 2
Read http://www.cplusplus.com/doc/tutorial/arrays.html
(and all the turotial sections before that if the subject in unfamiliar).
Step 3
Read http://www.cplusplus.com/doc/tutorial/files.html
Step 4
Post your attempt, as per step 1 someone will then be happy to help.
Hi there,
this is my first attempt and I need a help in solving the program.

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{

FILE *DATA; //READS the file

char c;
char no_prob[5];
char no_judges[5];

/* -no_problems ,judges , difficulty , time , scores
*/

/*This program reads the file as every character , What I need is if it can store the
Character values in the appropriate strings so that we can start using it, what I found out is
that first I need to work on it as characters until I split the data then convert using atoi and atof.
sample for the test data

5 6
3.0 2.5 1.8 2.8 3.2
2 10 6.0 2.1 6.5 7.0 8.0 7.5
3 30 2.3 7.0 7.0 6.0 7.0 8.0
1 15 6.5 8.0 6.5 7.0 8.7 9.0
4 40 5.0 6.6 4.7 3.0 7.0 5.0
5 35 5.0 6.5 4.0 8.0 6.7 5.8

*/

DATA = fopen("TEST.TXT", "r");

if (DATA == NULL)
printf("File doesn't exist\n");

else {
i=0;
j=0;



do {
c = getc(DATA); /* get one character from the file */
printf("c = %c\n", c);







}

while (c != EOF); /* repeat until EOF (end of file)
*/

}



fclose(DATA);


system("PAUSE");
return 0;
}
You know you could just use getline() to get a single line, then use the string functions to find the spaces/substr to get them out.
Topic archived. No new replies allowed.