Thread: Stupid question, repeating a loop iteration?

1. Stupid question, repeating a loop iteration?

Hey all, so I am working on a very simple program and it's almost to where I want it but I cannot figure out for life of me how to get this iteration to repeat when the user does not enter the value required

here is the portion of the code:

Code:
```         for (x = 1; x <= numb_of_grades; x = x + 1)
{   /*  begin 'for X' loop.  */
printf ("Enter grade #%i:", x);

if ( grade < 0 || grade > 100)
printf ("*** Invalid entry. Grade must be 0 to 100. ***");

else if ( grade >= 0 || grade <=100 )
while ( (c = getchar() != '\n') && c != EOF);

}  /*  end 'for X' loop.  */```
So all I want is the "invalid entry" to keep the user from going past the iteration he is on. So if he enters 4 grades I want it to do this:

*** Invalid entry. Grade must be 0 to 100. ***\

Right now it just continues on through the loop.

2. You may want to create another loop there, which will execute as long as grade < 0 || grade > 100 condition is true, and in the body will ask for the grade again.

Something akin to:
Code:
```do {
//ask the user politely for input
//if (input is inadequate) - beat the living... I mean, inform the user politely that it's erroneous
} while (input is inadequate);```

3. Code:
```int x, numb_of_grades, grade, gradeTotal = 0;	float finalavg = 0;
char c;

/*  Display initial greeting */
/*  ------------------------ */

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

do{

printf ("First, enter the number of grades to process:");
while ( (c = getchar() != '\n') && c != EOF);

if ( numb_of_grades < 2 );
printf ("You must enter at least 2! \n\n");

}while ( numb_of_grades < 2);

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