--- In [email protected], "mkaylad99" <[EMAIL PROTECTED]> wrote:
>
>  Where did I go wrong?

In several different ways you're going wrong:
1) you have not told us what your actual trouble is.
2) you have told us nothing about the program. We have to guess from
reading the program what MAY be your problem. Bad thing to start with.
3) You haven't told us what OS and what compiler you work with. It
looks as if you're using Turbo C under Windows, but you should have
told us in advance. Also the compiler you work with does not enforce
using ANSI C which is a bad thing to do.
4) It is fairly rude to not even write a short greeting or a closing
greeting. Also you have left out the "thanks for looking, guys/lads!"
5) See embedded remarks below.

> //****************************...
> //****************************...
> #include <stdio.h>
> 
> //function definition
> int displaynames();
> int displaygrades ();
> int entergrades ();

These are no useful function prototypes. What parameters do these
functions have? What types do these have?

> // 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');

It's far safer to declare "student" as an array of C strings or as an
array of arrays of chars, such like this:
  char student [5] [15] = { "", "", "", "", ""};
Also it's far easier to read your source code if you initialise C
strings like this:
  char student [15] = "";

Furthermore I don't see any good reason to use the constant 15 here;
it's much easier to change later on if you use:

#define  MAX_NAME_LENGTH  15
#define  MAX_STUDENTS      5
...
char student [MAX_STUDENTS] [MAX_NAME_LENGTH];
...

and later on a "for" loop to initialise all these C strings.

> 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];

Again, use
  int grades [MAX_STUDENTS] [MAX_GRADES];

> main ()

int main() is one of the two standard prototypes. Please, tell your
teacher to teach you ANSI C!

> { // 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();

The following only caused me the "Ouch!" feeling:

> 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;
> }

Do this in a "while" loop, please.

> // printf("\n dispORent = %i", dispORent); // debug line
> 
> displaynames (char); // call function to display the names

What shall this mean? Why do you name a data type as a parameter?

> if (dispORent == 1)
> displaygrades ();
> 
> if (dispORent == 2)
> entergrades ();

In the logical sense this makes more sense:
  switch (dispORent)
  { case 1:    /* display grades */
      displaygrades();
      break;

    case 2:    /* enter grades */
      entergrades();
      break;

    default:
      printf( "Only 1 or 2, please!\n");
      break;
  }

> 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;
> } 

Again, this should be put into a "while" loop.

> }
> while (enterdisplaymore = 1)
>   ;

What's the meaning of this empty "while" loop? What are you trying to
achieve here?

> 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

What the... you are writing C and use C++ comments???
Very bad idea. Either you write C++, or you write C. NEVER EVER mix up
C and C++ syntax! No compiler is required to accept such nonsense!

> 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;
> } 

Again: such checks should be performed inside a "while" loop.

> // printf("studentselected = %i", studentselected); //debug
> 
> return (); 

And what shall these parentheses mean? "return" is an operator which
in this case should return one int value; "return" is not a function.

> } 
> 
> // 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.

Again, using C++-style comments in C code is a BAD idea.

> { 
> 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 ();

Again: "return" is not a function.

> // set up for entering grades for a student already selected 
> 
> Additional Details
> 
> 56 minutes ago

What does this mean? If this is supposed to be a hint to us, the
readers of your post, then please tell us what's the use of such a
piece of data to us. As we can't know what to make out of this piece
of data, it is no information to us: in general "information" is
defined as data with meaning.

> 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

Any further questions, please let us know. But be aware that -as you
can see by my post- you will get replies which are not too humble; we
are not here to be humble but to help you become a (better) programmer
or in the end maybe even a real software developer.
[Thanks to Thomas for this clear distinction.]

Regards,
Nico

Reply via email to