Write a program that asks the user to input an integer between 25 and 50, inclusive. Utilize a WHILE loop to test for INVALID input. If the input is INVALID, the loop will repeat, and ask the user to try again. The pseudocode looks like this: Prompt user to input an integer between 25 and 50 Accept the input from the user Test for invalid input (HINT: use a while loop and the OR operator with 2 relational expressions. You are testing if the number is less than 25 OR greater than 50, because you are testing for INVALID input to repeat the body of the loop) { display a user-friendly message to try again accept the input from the user } Display a user-friendly message echoing the valid input. Validate your code by running it with valid input and invalid input.
CODE IN C:
#include <stdio.h>
int main()
{
int number ;
printf("Enter an integer between 25 and 50 : ");
scanf("%d",&number);
while(number < 25 || number > 50){
printf("Invalid input... please try again.\n");
printf("Enter an integer between 25 and 50 : ");
scanf("%d",&number);
}
printf("You entered a valid value %d\n", number);
return 0;
}
OUTPUT:
Get Answers For Free
Most questions answered within 1 hours.