i've got a massive problem that i've been trying to independently learn how to figure out, as my prof explains so little information that's actually pertinent to the assigned homework!
here's the problem, it seems like a dusey at first:
The purpose of this homework is to reinforce ideas of decisions and loops, if else and while, and sequence.
the professor keeps his grades in a file similar to the following
0000 10 10 10 10 20 20 20 100 100 100
1121 10 9 10 7 20 20 19 100 95 100
3321 9 8 9 18 19 19 19 88 75 92
etc,
The first number is the student number. The next 10 numbers are scores the student has earned. The first line of the file is a line telling the total number of points possible for each of the exercises. You can tell this line since it has a student number of 0000. We know that Dr. Eggen has exactly 8 students in his class. Your task is to read the information from the file using unix redirection of stdin, and calculate an average score for each of the students, points earned divided by points possible. You then suggest a grade for that student, using the scale
90-100 A
80-89 B
70-79 C
60-69 D
below 60 F
You must make up a file of data containing the 8 students, and must print a suitably formatted output.
i've already made the text file with made-up grades, but i can't for the life of me figure out how to incorporate that into the code of the c programme! here is what i've got so far:
Code:
#include <stdio.h>
int main ()
{
int student; //this is what i figured the 4 digit student id number would be in C
int num1; /*these int nums are what i thought would be the individual assignment grades for each student, each student being represented by the four digit number in the text file */
int num2;
int num3;
int num4;
int num5;
int num6;
int num7;
int num8;
int num9;
int num10;
int sum;
sum=num1 + num2 + num3 + num4 + num5 + num6 + num7 + num8 + num9 + num10;
float avg;
avg=(sum) / 400;
float score;
score=avg * 100;
scanf("%d", &student);
scanf("%d", &num1);
scanf("%d", &num2);
scanf("%d", &num3);
scanf("%d", &num4);
scanf("%d", &num5);
scanf("%d", &num6);
scanf("%d", &num7);
scanf("%d", &num8);
scanf("%d", &num9);
scanf("%d", &num10);
printf("Average is: %f\n", &avg);
printf("Score is %f\n", &score);
if (score >= 90)
{
printf("A");
}
else {
if (score >=80)
printf("B");
}
else {
if (score >=70)
printf("C");
}
else {
if (score >=60)
printf("D");
} else {
printf("F");
}
/* everything ok return without error */
return 0;
}
that's a direct copy-paste.
he wants me to use the a.out < txtfile command in unix, but i need to know how to make c parse the text file correctly! please somebody help me. i've been slaving over this for six straight hours. i'm tearing my hair out over my teacher's lack of eponymous duty!!!
ANY help is greaaatly appreciated, thank you