For starters, I am new to C and programming in general. I have more experience with PowerShell and bash scripting, so apologies in advance for errors with headers, indentation, syntax, etc. Anyway, I'm trying to complete this program for a class, but I've had some trouble with one particular section, so I'm looking for some guidance as I'm pretty lost right now.
To provide some background: I'm supposed to allow a user to enter a user code between 6 and 10. This code uniquely identifies the user, who would then be asked for input for several other integer values, which would be totaled and averaged at the end. However, the user must be able to start the program again and enter another number (between 6 and 10); the user must then go through the previous process again to finish the program.
My problem is I cannot use if statements, break, continue, exit, abort or goto; I must use a do while loop to figure out when the user is done entering input; and I must provide error messages for when the user enters the wrong input, prompting them to enter it again.
With what I've posted below, I cannot figure out how to give the user an option to continue and/or exit without using if, break, continue, etc and while also prompting for error messages. I'm probably overthinking something but if anyone can provide some insight I would greatly appreciate it.
#include<stdio.h>
main()
{
int usercode; /* setting variables for user code */
do
{
printf ("Please enter your user code: ");
scanf("%1d", secid); /* user must input 1 digit code */
} while(secid >= 6 || secid <= 10); /* code must be between numbers 6 and 10 */
}
seciddefinition. I guess you copied this from a printed book and misread%ldas%1d, withlong int secid;previously defined. Or, long live 20th century typewriters lacking a1key!scanfdoes not return until another entry is made. The danger too, is if you limit input intoscanfthe extra characters remain in the input buffer. But since you go on to restrict the input withwhile(secid >= 6 || secid <= 10);I don't see the point of it.