I'm doing a program for school and this piece of code won't work...
// This function gets the user to input the percent grade and returns the
// rounded version of that value.
int input_grade (void)
{
// This variable is the percent grade and is input by the user. It is set to 150
// so the 'while' loop will function correctly.
float per_grd=150;
// This variable hold the value of the rounded percent grade.
int round_grd;
// This loop lets the user re-enter the percentage grade if it is invalid.
while (per_grd>100 || per_grd <0)
{
// Gets the user to input the percentage grade.
printf ("Enter percentage grade: ");
cin >> per_grd;
// The following checks it make sure the input is valid and if it is not, it
// displays an error message.
if (per_grd>100 || per_grd <0)
{
// Prints an error message to the screen, gets the user to press
// any key to continue then clears the screen. The loop then restarts.
printf ("\nTHAT IS AND INVALID ENTRY...PLEASE RE-ENTER!\n\n");
system ("PAUSE");
system ("CLS");
}
else
{
// Calls the round function then assigns the value to the 'round_grd'
// function.
round_grd=per_grd_round(per_grd);
}
}
// Returns the value of the rounded grade.
return round_grd;
}
... When you enter a letter the loop works, but it won't let you re-enter the value and just loops continuously.
Thanx, Ian
PS. I have attached the full code... please take a look and reply...