Hi guys, I've got the code all written but there are a ton of runtime errors that need to be fixed, mainly with calculations and inputting data into the array. I also need to use pointers when referencing the scores array, and I cannot for the life of me get the pointers concept down! Here is the code I have... This is an extremely important assignment that is due at midnight tonight, so any help would be really great!

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

int menu();
void heading(void);
double getgrades(double s[]);
void showgrades(double s[], int count);
double changegrade(double s[], int count);
double findgrades(double s[], int count);
void message(char msg[]);
void show(double s[], int count);
int menuerror(int min, int max, char prompt[]);
int prompt(char msg[]);
int quit(void);

/* ================================================================== */

// ** Functions **

int main()
{

	int TRUE = 1;
	int FALSE = 0;
	int select, end = TRUE;
	int count=0;
	double scores[101];

	do
	{

		select = menu();
		switch (select)
		{
		case 1: getgrades(scores); break;
		case 2: showgrades(scores, count); break;
		case 3: changegrade(scores, count); break;
		case 4: findgrades(scores, count); break;
		case 5: end = quit(); break;
		default: message("\n\nPlease make a selection between 1 and 5.\a");
		}
	}

	while (end);
	return 0;
}
/*  ================================================================  */

int menu()
{
	int choice;

	system("cls");

	printf("Grade Score Database\n\n");
	printf("1  =  Get Grades\n");
	printf("2  =  Show Grades\n");
	printf("3  =  Change Grade\n");
	printf("4  =  Find Grade\n");
	printf("5  =  Quit\n\n");
	choice = menuerror(1, 5, "Enter your selection");

	return(choice);
}
/*  ================================================================  */

void heading()
{
	system("cls");
	printf("Grade Score Database\n\n\n");
	return;
}
/*  ================================================================  */

double getgrades(double *s)
{
	double scores[101];
	int z, count=0;

	for (z = 1; z < 101; z++)
	count += 1;
	{
	printf("Enter a grade, or 0 to quit: ");
	scanf("%d", &scores[z]);
	}

	
	while (&scores[z] != 0);

	return(count);
}
/*  ================================================================  */

void showgrades(double *s, int count)
{
	int z;
	double scores[101];
	

	system("cls");

	printf("Score Report\n\n");
	printf("_Position________Grade_\n\n");
	for (z = 1; z < 101; z++)
	{
		printf(" %2d%2lf\n\n", z, scores[z]);
		
	}
	
	printf("Press ENTER to return to the Main Menu...");
	getchar();


}
/*  ================================================================  */

double changegrade(double *s, int count)
{
	int z;
	double scores[101];

	for (z = 1; z < 101; z++)
	
	{
	printf("Enter grade position to edit, or 0 if no changes: ");
	scanf("%d", &z);
	printf("Enter new grade for position %d: ", z);
	scanf("%d", &*(scores+z));
	}
	while (*(scores+z) != 0);

	return 0;
}
/*  ================================================================  */

double findgrades(double *s, int count)
{
	int z, low, high;
	double scores[101];

	printf("Enter lowest grade to locate: \n");
	scanf("%d", &low);
	printf("Enter highest grade to locate: \n");
	scanf("%d", &high);
	
	printf("The following grades are within the specified range: \n\n");
	for (z = 1; z < 101; z++)

	if (scores[z] > low || scores[z] < high)
	{
		show(scores, count);
	}
	printf("Press ENTER to return to the Main Menu...");
	getchar();
		 return 0;
}
/*  ================================================================  */

void show (double *s, int count)
{
  int z;
  double scores[101];

for (z = 1; z < 101; z++) printf ("%4d", scores[z]);
printf ("\n");

}
/*  ================================================================  */

void message(char msg[])
{
	printf("%s\n\n", msg);
}
/*  ================================================================  */

int menuerror(int min, int max, char item[])
{
	int z;
	printf("%s from %d to %d: ", item, min, max);
	scanf("%d%*c", &z);
	while (z < min || z > max)
	{
		message("\nError in range.  Press Enter to continue.\a");
		printf("%s from %d to %d: ", item, min, max);
		scanf("%d%*c", &z);
	}
	return(z);
}

/*  ================================================================  */

int prompt(char msg[])
{
	int z;
	do
	{
		printf("%s (Y/N)? ", msg);
		z = toupper(getchar());
		if (z != 'Y' && z != 'N') printf("\nError, please enter Y or N only.\n");
	}
	while (z != 'Y' && z != 'N');
	return(z);
}
/*  ================================================================  */

int quit()
{
	int TRUE = 1;
	int FALSE = 0;
	int z, end = TRUE;

	z = prompt("\nEnd program\a");
	if (z == 'Y')
	{
		system("cls");
		message("\nGrade Score Database Closed Succesfully.");
		end = FALSE;
	}
	return(end);
}
/*  ================================================================  */

>I cannot for the life of me get the pointers concept down
Forgive me, but you don't seem to get the concept of loops, nor the concept of proper
format operant for printf() or scanf() neither.

Just an example of your code:

double getgrades(double *s) /* s is never used */
{
	double scores[101];
	int z, count=0;

	for (z = 1; z < 101; z++) /* count gets incremented 100 times */
	count += 1; /* after for loop ends count holds 100 */
	{ /* braket does nothing */
	printf("Enter a grade, or 0 to quit: "); /* display to screen once */
	scanf("%d", &scores[z]); /* wrong format %d is for integers, scores[101] is a double*/
	}/* worthless braket */

	/*
         * behold the power of an infinite loop
         */
	while (&scores[z] != 0);  /* if the address of scores[101] is not 0 then loop */

	return(count); /* count is an int, this function returns a double */
}

This kind of situation is all over your code. Check the convection format for every printf() and scanf(). You have some more infinite loops than the one I pointed out.

Wow, you're right. I'm just having a really hard time focusing on this assignment. Close friend died a few days ago so things have been chaotic. I usually at least understand the basic stuff! I really appreciate your taking the time to comment on that though. Definitely gives me a good idea of where to begin. Hopefully the rest of the code isn't too bad or there's no way I'll have this turned in by midnight!

Let me point something about double floating point conversion format for printf()
%lf evokes an undefined behavior[*] using it with printf(), if your compiler is not an implementation of C99, and most are not at this point.

When you try to display a double with printf() you don't need to specify that is a double since printf works with values and internally any float is promoted to a double anyway.
So printf( "%f\n", double_variable ); is Ok.

Now scanf() is another story. It is necessary to tell scanf what is going to read since is done via a pointer, thus the need of the & operator. If a double is what you want you need to do it as: scanf( "%lf", &double_variable ); [*] Anything can happen. It is not specified by the Standards.

Thanks, I'm gettin there. Still just confused though because I'm not sure how to get rid of the infinite loops. My brain is exhausted. This is what I have:

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

int menu();
double getgrades(double s[]);
void showgrades(double s[], int count);
double changegrade(double s[], int count);
double findgrades(double s[], int count);
void message(char msg[]);
void show(double s[], int count);
int menuerror(int min, int max, char prompt[]);
int prompt(char msg[]);
int quit(void);

/* ================================================================== */

// ** Functions **

int main()
{

	int TRUE = 1;
	int FALSE = 0;
	int select, end = TRUE;
	int count=0;
	double scores[101];

	do
	{

		select = menu();
		switch (select)
		{
		case 1: getgrades(scores); break;
		case 2: showgrades(scores, count); break;
		case 3: changegrade(scores, count); break;
		case 4: findgrades(scores, count); break;
		case 5: end = quit(); break;
		default: message("\n\nPlease make a selection between 1 and 5.\a");
		}
	}

	while (end);
	return 0;
}
/*  ================================================================  */

int menu()
{
	int choice;

	system("cls");

	printf("Grade Score Database\n\n");
	printf("1  =  Get Grades\n");
	printf("2  =  Show Grades\n");
	printf("3  =  Change Grade\n");
	printf("4  =  Find Grade\n");
	printf("5  =  Quit\n\n");
	choice = menuerror(1, 5, "Enter your selection");

	return(choice);
}
/*  ================================================================  */

double getgrades(double *s)
{
	double scores[101];
	int z, count=0;

	for (z = 1; z < 101; z+=1)
	count += 1;
	
	do
	{
	printf("Enter a grade, or 0 to quit: ");
	scanf("%lf", &scores[z]);
	}

	
	while (&scores[z] != 0);

	return(scores[101]);
}
/*  ================================================================  */

void showgrades(double *s, int count)
{
	int z;
	double scores[101];
	

	system("cls");

	printf("Score Report\n\n");
	printf("_Position________Grade_\n\n");
	for (z = 1; z < 101; z++)
	{
		printf(" %2d%2f\n\n", z, scores[z]);
		
	}
	
	printf("Press ENTER to return to the Main Menu...");
	getchar();


}
/*  ================================================================  */

double changegrade(double *s, int count)
{
	int z;
	double scores[101];

	for (z = 1; z < 101; z++)
	
	{
	printf("Enter grade position to edit, or 0 if no changes: ");
	scanf("%d", &z);
	printf("Enter new grade for position %d: ", z);
	scanf("%f", &*(scores+z));
	}
	while (*(scores+z) != 0);

	return 0;
}
/*  ================================================================  */

double findgrades(double *s, int count)
{
	int z, low, high;
	double scores[101];

	printf("Enter lowest grade to locate: \n");
	scanf("%lf", &low);
	printf("Enter highest grade to locate: \n");
	scanf("%lf", &high);
	
	printf("The following grades are within the specified range: \n\n");
	for (z = 1; z < 101; z++)

	while (scores[z] > low || scores[z] < high)
	{
		show(scores, count);
	}
	printf("Press ENTER to return to the Main Menu...");
	getchar();
		 return 0;
}
/*  ================================================================  */

void show (double *s, int count)
{
  int z;
  double scores[101];

for (z = 1; z < 101; z++) printf ("%f", scores[z]);
printf ("\n");

}
/*  ================================================================  */

void message(char msg[])
{
	printf("%s\n\n", msg);
}
/*  ================================================================  */

int menuerror(int min, int max, char item[])
{
	int z;
	printf("%s from %d to %d: ", item, min, max);
	scanf("%d%*c", &z);
	while (z < min || z > max)
	{
		message("\nError in range.  Press Enter to continue.\a");
		printf("%s from %d to %d: ", item, min, max);
		scanf("%d%*c", &z);
	}
	return(z);
}

/*  ================================================================  */

int prompt(char msg[])
{
	int z;
	do
	{
		printf("%s (Y/N)? ", msg);
		z = toupper(getchar());
		if (z != 'Y' && z != 'N') printf("\nError, please enter Y or N only.\n");
	}
	while (z != 'Y' && z != 'N');
	return(z);
}
/*  ================================================================  */

int quit()
{
	int TRUE = 1;
	int FALSE = 0;
	int z, end = TRUE;

	z = prompt("\nEnd program\a");
	if (z == 'Y')
	{
		system("cls");
		message("\nGrade Score Database Closed Succesfully.");
		end = FALSE;
	}
	return(end);
}
/*  ================================================================  */
double getgrades(double *s) 
{
     /* double s is not used in your function at all */
	double scores[101];
	int z, count=0;

	for (z = 1; z < 101; z+=1) /* This */
	count += 1;           /* and this is the same that */
	                     /* count = 100;  but with a lot more work */
	do
	{
	printf("Enter a grade, or 0 to quit: ");
	scanf("%lf", &scores[z]);
	}

	/* haven't fix the forever loop, that expression never changes */
        /* z is always 101 at this point */
	while (&scores[z] != 0);/* the address of scores[101] is never 0*/
                                /* if it were your program would crash */

        return(scores[101]); /* never gets to this point */
        /* all that work to return just the last score? */
}

Perhaps is time to stop using scanf() to read a floating-point; and do some checking of what the user enters. Here is a little example of how you might do that.

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

int main(void)
{
   double value; 
   char *end, buff[32];
   int status = 0;

   do
   {
      fputs("Enter a floating-point number: ", stdout);
      fflush(stdout);

      /* read input string and check for initial white space */
      if( fgets( buff, sizeof buff, stdin ) && !isspace( *buff ) )
      {
         /* try to convert the string read into a double */
         if((value = strtod(buff, &end))&&(*end == '\n' || *end == '\0'))
              status = 1;
      }

   } while ( !status ); /* reapeat if input was not correct */
   printf( "value = %g\n", value );
   return 0;
}
This article has been dead for over six months. Start a new discussion instead.