i have written this program to calculates grades. Its works well but i need to add a error message if atleast two grades are not added and i am kinda stuck. here is my code any help would be appreciaed.

Code:
```#include <stdio.h>
int main(void)
{

/* Declare variables. */

int invalid_entry = 0;
float average;

/* Output initial greeting and introduce program */
/* --------------------------------------------- */

printf ("This program calculates the average of as many grades as you wish to enter.\n\n");

/* Prompt user for number of grades to be entered. */
/* ------------------------------------------------*/

printf ("First, enter the number of grades to process: ");

/* Output appropriate message based on number of grades entered. */
/*---------------------------------------------------------------*/

for (i = 1; i <= number_of_grades; i++)

{

/* Prompt user for grades. */
/* ----------------------- */

printf ("Enter grade #%d: ", i);

/* If grade is out of range output error message, otherwise output grade entered.*/

/* ----------------------------------------------------------------------------- */

{
printf ("*** Invaid entry. Grade must be 0 to 100.***\n");
i --;
}

else
{

/* Assign values */
/* --------------*/

}
} // end for loop

/* Calculate average and display output */
/* ------------------------------------ */

/* Assign values to letter grades */
/* -------------------------------*/

if( average <= 63.0 )

{
printf( "You have a letter grade of F\n" ) ;
}
else if( average <= 66.0 )
{
printf( "You have a letter grade of D\n"  ) ;
}
else if( average <= 69.0 )
{
printf( "You have a letter grade of D+\n"  ) ;
}
else if( average <= 73.0 )
{
printf( "You have a letter grade of C-\n" ) ;
}
else if( average <= 76.0 )
{
printf( "You have a letter grade of C\n" ) ;
}
else if( average <= 79.0 )
{
printf( "You have a letter grade of C+\n" ) ;
}
else if( average <= 83.0 )
{
printf( "You have a letter grade of B-\n"  ) ;
}
else if( average <= 86.0 )
{
printf( "You have a letter grade of B\n"  ) ;
}
else if( average <= 89.0 )
{
printf( "You have a letter grade of B+\n"  ) ;
}
else if( average <= 93.0 )
{
printf( "You have a letter grade of A-\n"  ) ;
}
else
{
printf( "You have a letter grade of A\n"  ) ;
}

} //end main```

2. You can use a counter, say, int num_invalid_grades = 0 and increment it (num_invalid_grades++) every time someone doesn't input a valid grade and test:

Code:
```
{
exit(0);
}```
exit() is declared in <stdlib.h> and it means you want to close the program (probably because of an error).

Edit:

Another way is using mod (the operation returns the remainder of the division):

Code:
```num_invalid_grades = total_grades % num_of_grades;
{
printf("Exiting the program...");
exit(0);
}```

3. i do not want to the program to exit it want it to tell the user they must enter atleast two grades. i tried a if else loop but i keep getting errors, i thought it would be the same as when i have the user enter a grade between 0-100. if i put a negative grade it prompts the user to put in the proper values.

4. Originally Posted by fenway81
want it to tell the user they must enter at least two grades.
Have you tried the logic I posted ?

Edit:

I noticed some problems in your code: @line 47 the correct decrement is i-- not i -- (notice the whitespace between i and '--') however, you don't need to decrement i because you're incrementing it in the for loop. @line 117 you forgot to write return 0 (int main expects you return 0):

Code:
```
int main(void)
{

return 0;
}```
consider writting main like that as the first thing you will do in your code

Compare your code with the below one:

Code:
```#include <stdio.h>
#include <stdlib.h>

int main(void)
{

/* Declare variables. */

float average;

/* Output initial greeting and introduce program */
/* --------------------------------------------- */

printf ("This program calculates the average of as many grades as you wish to enter.\n\n");

/* Prompt user for number of grades to be entered. */
/* ------------------------------------------------*/

printf ("First, enter the number of grades to process: ");

/* Output appropriate message based on number of grades entered. */
/*---------------------------------------------------------------*/

for (i = 1; i <= number_of_grades; i++)

{

/* Prompt user for grades. */
/* ----------------------- */

printf ("Enter grade #%d: ", i);

/* If grade is out of range output error message, otherwise output grade entered.*/

/* ----------------------------------------------------------------------------- */

{
printf ("*** Invaid entry. Grade must be 0 to 100.***\n");
}

else
{

/* Assign values */
/* --------------*/

}
}  // end for loop

{
exit(0);
}

/* Calculate average and display output */
/* ------------------------------------ */

/* Assign values to letter grades */
/* -------------------------------*/

if( average <= 63.0 )

{
printf( "You have a letter grade of F\n" ) ;
}
else if( average <= 66.0 )
{
printf( "You have a letter grade of D\n"  ) ;
}
else if( average <= 69.0 )
{
printf( "You have a letter grade of D+\n"  ) ;
}
else if( average <= 73.0 )
{
printf( "You have a letter grade of C-\n" ) ;
}
else if( average <= 76.0 )
{
printf( "You have a letter grade of C\n" ) ;
}
else if( average <= 79.0 )
{
printf( "You have a letter grade of C+\n" ) ;
}
else if( average <= 83.0 )
{
printf( "You have a letter grade of B-\n"  ) ;
}
else if( average <= 86.0 )
{
printf( "You have a letter grade of B\n"  ) ;
}
else if( average <= 89.0 )
{
printf( "You have a letter grade of B+\n"  ) ;
}
else if( average <= 93.0 )
{
printf( "You have a letter grade of A-\n"  ) ;
}
else
{
printf( "You have a letter grade of A\n"  ) ;
}
return 0;
} //end main```

5. Originally Posted by fenway81
i do not want to the program to exit it want it to tell the user they must enter atleast two grades
Do you mean that you want to repeat the input if the user enters a number less than two at this point?
Code:
```printf ("First, enter the number of grades to process: ");