Where did I go wrong?
//****************************...
//****************************...
#include <stdio.h>
//function definition
int displaynames();
int displaygrades ();
int entergrades ();
// global variables
char student1[15] = {'\0'};
char student2[15] = {'\0'};
char student3[15] = {'\0'};
char student4[15] = {'\0'};
char student5[15] = {'\0'};
int studentselected = 0;
char student[15] = ('\0');
int dispORent = 0; // when changed, 1 = display grades, 2 = enter
grades
// here is the array for the grades, 5 students, 10 grades
int grades[5][10];
main ()
{ // main
//we are going to call the rows irows and the columns icol
int irow = 0;
int icol = 0;
int enterdisplaymore = 1;
//here is a nested for loop to initialize the array, good practice!
for (irow = 0; irow < 5; irow++)
{ // outer for
for (icol = 0; icol < 10; icol+)
grades[irow][icol] = 0;
/*****************************...
// print out the 0's in the arrays - debug lines
for (irow = 0; irow < 5; irow++)
{ // outer for
for (icol = 0; icol < 10; icol++)
{ // inner for
printf("grades[%d][%d] = %d\n", irow, icol, grades[irow][icol]);
} // inner for
} // outer for
//****************************...
// get the 5 students names and put them into an individual array.
printf ("\nEnter name for student 1: ");
scanf ("%s", student1);
// printf ("\nname for student 1 is: %s", student1); // debug line
printf ("\nEnter name for student 2: ");
scanf ("%s", student2);
printf ("\nEnter name for student 3: ");
scanf ("%s", student3);
printf ("\nEnter name for student 4: ");
scanf ("%s", student4);
printf ("\nEnter name for student 5: ");
scanf ("%s", student5);
//****************************...
// This is now a continuous loop, so the user doesn't keep entering
the
// names over and over again, it should be to display or enter grades.
do
{
// display the grades or enter grades?
clrscr();
try_again_start:
printf("\nDo you want to display the grades for a student or enter
grades?");
printf("\n\tEnter 1 to display grades: ");
printf("\n\tEnter 2 to enter grades: ");
printf("\n\nEnter Selection: ");
scanf ("%i", dispORent);
// error checking
if (dispORent < 1 || dispORent > 2)
{
printf("\n\nPlease enter either a 1 or a 2 only.");
goto try_again_start;
}
// printf("\n dispORent = %i", dispORent); // debug line
displaynames (char); // call function to display the names
if (dispORent == 1)
displaygrades ();
if (dispORent == 2)
entergrades ();
try_again_more:
printf("\n\nDo you want to enter or display more grades?");
printf("\n\tEnter 1 to continue.");
printf("\n\tEnter 2 to stop.");
printf("\n\n Enter your selection: ");
scanf("%d", &enterdisplaymore);
// error checking
if (enterdisplaymore < 1 && enterdisplaymore > 2)
{
printf("\n\nPlease enter either a 1 or a 2 only.");
goto try_again_more;
}
}
while (enterdisplaymore = 1);
getchar();
} // main loop
/*****************************...
/ Functions
/
/*****************************...
//display to the user a list of students and ask which one they would
like to enter grades for and what week
int displaynames ()
{
clrscr();
try_again_student:
printf("\n\nHere is a listing of students for selection: ");
printf(" \n\tEnter 1 for %s", student1);
printf(" \n\tEnter 2 for %s", student2);
printf(" \n\tEnter 3 for %s", student3);
printf(" \n\tEnter 4 for %s", student4);
printf(" \n\tEnter 5 for %s", student5);
printf("\n\nEnter Student Number: ");
scanf("%s", &studentselected);
// error checking
if (studentselected < 1 || studentselected > 5)
{
printf("\n\nPlease enter either a 1, 2, 3, 4 or 5 only");
goto try_again_student;
}
// printf("studentselected = %i", studentselected); //debug
return ();
}
// displays the grades of an already selected student
int displaygrades ()
// sutdentselected is a global value and has already been selected.
// Now what to do with it, we are suppose to display the grades and
then
// come up with an average. So determine which array is this persons,
add
// all the non-zero grades, keep track of the number of grades
entered for
// the average. Print the grades, each on a separate line and then
print out
// the average.
{
int iGradeCell = 0; // index into the array
int count; //variable for counting the for loop
int NumberOfGrades = 0;
int SumOfGrades = 0.0;
float average = 0.0;
// printf ("inside displaygrades"); // debug
// getchar(); // debug
//determine array cell from studentselected variable
iGradeCell = studentselected - 1; // this is the row
// printf ("\nstudentselected = %i", studentselected); //debug
// printf ("\niGradeCell = %i", iGradeCell); //debug
// getchar(); //debug
if (studentselected == 1)
printf ("\n\nThe grades for %s are:", student1);
if (studentselected == 2)
printf ("\n\nThe grades for %s are:", student2);
if (studentselected == 3)
printf ("\n\nThe grades for %s are:", student3);
if (studentselected == 4)
printf ("\n\nThe grades for %s are:", student4);
if (studentselected == 5)
printf ("\n\nThe grades for %s are:", student5);
for (count = 0; count < 10; count++) // this is to look at the columns
{
// printf ("\ncount = %i", count); // debug line
// printf ("\n grade in cell 0 0= %i", grades[iGradeCell][count]); //
debug line
if (grades[iGradeCell][count] != 0)
{
// printf ("\n inside the for and while loop"); //debug
printf ("\nWeek %i = %i", count+1, grades[iGradeCell][count]);
NumberOfGrades = NumberOfGrades + 1;
SumOfGrades = SumOfGrades + grades[iGradeCell][count];
}
}
average = SumOfGrades / NumberOfGrades;
printf ("\n\nThe average grade is: %.2f", average);
return ();
// set up for entering grades for a student already selected
Additional Details
56 minutes ago
int iweek = 0; column
int iGradeCell = 0;
int iWeekCell = 0;
int igrade = 0;
int entermore = 1; more grades for the same person 1 = yes 2 = no
//determine array cell from studentselected variable
iGradeCell = studentselected - 1; // this is the row
do
{
try_again_week:
printf ("\n\nWhat week (1-10) do you want to enter grades for: ");
scanf ("%d", &iweek);
// error checking
if (iweek < 1 || iweek > 10)
{
printf("\n\nEnter numbers that from 1 to 10 only.");
goto try_again_week;
}
// printf("\nweek entered was %d", iweek); //debug
iWeekCell = iweek - 1;
printf("\nWhat grade (0 - 100) would you like to enter: ");
scanf("%d", &igrade);
// printf("\ngrade entered = %d", igrade); // debug
grades [iGradeCell][iWeekCell] = igrade;
// printf ("\n value entered =%d", grades [iGradeCell]
[iWeekCell]); //debug