Code:
1 /************************************************** ***
2 * A Program To Manage Grades *
3 * written by: stormy *
4 * 9/1/05 *
5 ************************************************** ****/
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include <math.h>
10
11 #define BUFFER 100
12
13 char name[BUFFER]; /* students name */
14 //char assignment[BUFFER]; // don't need that
15 //char *Nassignment[BUFFER][10]; would be a pointer to an array of 100 strings
15 char Nassignment[BUFFER][10]; // 100 grades a 10 chars
17 // int grade; don't need that
18 int count = 0, i = 0; /* counters */
19 int ngrade[BUFFER]; /* array to hold grades */
20
21 int main()
22 {
23
24 //////// TAKE IN INITIAL INFO ////////
25 printf("Student name:");
26 scanf("%s", name);
27
28 //////// BEGIN LOOP FOR GRADES ////////
29
30 printf("How many grades?:");
31 scanf("%d", &num_grades); // should be tested for <= 100
32
33 while (i < num_grades) {
34
35 printf("Assignment:");
36 scanf("%s", Nassignment[i]); // read directly
37 // Nassignment[count][count] = assignment; cant' assign this way
38 printf("Grade:");
39 scanf("%d", &ngrade[i]); // read directly
40 // ngrade[i] = grade;
41 // ++count; don't need that
42 ++i;
43 }
44
45 //////// DO THE MATH ////////
46 // int i = 0; // allready have one
46 i = 0;
47 // int k = 1; // not needed
48 int result = 0;
49
50 while (i < count) {
51 // result = ngrade[i] + ngrade[k]; // would overflow
51 result += ngrade[i];
52 ++i;
53 // ++k; don't need that
54 }
55
56 //////// OUTPUT FORMATTED RESULTS ////////
57 i = 0;
58 printf("\t\tStudent Name: %s\n", name);
59 printf("================================================== ===\n");
60 while (i < count) {
61 // printf("%s\t\t%d\n", *Nassignment[i], ngrade[i]); wrong indirection
61 printf("%s\t\t%d\n", Nassignment[i], ngrade[i]);
62 i++;
63 }
64 printf("Final Average:%d\n", result / count);
65 printf("================================================== ===\n");
66
67 return(0);
68 }
Hope I have not overlooked anything.
Kurt