Hi, I'm making a program for a uni assignment where the user inputs an initial velocity and angle and the program will calculate a projectiles maximium height and range from these variables assuming it is launched from a 300m cliff.

The problem I am having is ensuring that the inputs are correct, ie that the user inputs an angle between 90 and -90 degrees. The program needs to not let the user input a character and also recognise when an angle is a multiple of 360 above or below an angle within the allowed range, ie 361 is equal to 1 and therefore allowed.

I have tried the following code:

The problem with this code is that if a user is to enter a number not within the range, ie 100 and then a letter, ie a, the code will endlessly loop the error message "The angle entered was not within the specified range, please enter a correct value"Code:while(1){ while(scanf("%f", &theta) != 1){ printf("please enter a real number for your angle:\nangle = "); scanf("%s", &theta); } while(theta >= 270){ //Makes angles that are greater than 270 but still within the range on a scale for the program to use theta = theta - 360; } while(theta <= -270){ theta = theta + 360; } while(theta>90 || theta<-90){ //tells user to reenter angle if it was not within the specified range printf("The angle entered was not within the specified range, please enter a correct value:\nangle = "); scanf("%f", &theta); } if(theta >= -90 && theta <= 90) break; }

Any help in making these loops work so that any combination of incorrect inputs won't bomb out the program or start more infinte loops of error messages would be greatly appreciated