Hello.,
I'm working on my school assignment and the condition is to use post-test loop trying to get following result:
---------------------------------------------------------------
Enter the Section Code: 0
Invalid value entered. Must be 1 to 4, please re-enter: 1
Enter the Student's ID:
---------------------------------------------------------------
this is the assignment condition:
When the program starts it will prompt the user for the Section Code (a number between 1 and 4 that identifies each unique class that are running concurrently in the semester). You must use a post-test loop for this loop.
------------------
I must use post-test loop for validating the input as well as moving on to the next questions, but post-test loop executes the statement at least once so when Im trying to use do/while loop, when the condition is false(numbers selected out of 1-4 range) it goes straight back to the beginning of the loop, when i need it to jump to the second statement printf("Invalid value entered. Must be 1 to 4, please re-enter:"), is it possible to redirect within the loop?
Here is my code:
#include<stdio.h>
main()
{
int sec_code; int i;
printf("\n");
printf("Enter the Secion Code:");
scanf("%d", &sec_code);
do
{
printf("\n");
printf("Ivalid value entered. Must be 1 to 4, please re-enter:");
scanf("%d", &sec_code);
}while(sec_code < 1 || sec_code >4);
}
Any help would be greatly appreciated