Okay, I did a bit more work, and it's displaying all the names and scores right, but I'm having problems figuring out how to keep a total of all the scores so I can use them to find the average and who has the highest and lowest scores. Here's my code so far:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#define ARRAY_SIZE 30
int main(int argc, char *argv[])
{
FILE* spStudents;
int average;
char buffer[10001];
char student[ARRAY_SIZE];
int score;
int sum;
int target;
printf("Welcome! This program will read a text file containing names\n");
printf("and scores of 30 students enrolled in a class. The program will\n");
printf("find the class average, find the student with the lowest\n");
printf("score, and find the student with the highest score.\n\n");
spStudents = fopen("L:\\CIS 161\\Chapter VIII pt 1\\students.txt", "r");
if (spStudents == NULL)
{
printf("Error opening students.txt for reading.\n");
exit (100);
}
fgets(buffer, 10000, spStudents);
printf("Here are the names and scores:\n");
while(feof(spStudents) == 0)
{
sscanf(buffer, "%s%d", student, &score);
printf("%s %d\n", student, score);
fgets(buffer, 10000, spStudents);
}
score += sum;
average = sum / 30;
printf("\nThe class average is: %d\n", &average);
if (score == 99)
{
printf("The person with the highest score is: %s\n", &student);
}
if (score == 59)
{
printf("The person with the lowest score is: %s\n\n", &student);
}
printf("If you're looking for a particular score, please enter it, and\n");
printf("I'll tell you if someone has that score: ");
scanf("%d", &target);
if (target == score)
{
printf("%s has that score!\n", &student);
}
if (target != score)
{
printf("Sorry, no one has that score.\n");
}
fclose(spStudents);
system("PAUSE");
return 0;
}