I use a loop to determine if input is correct and if wrong to ask again till input is valid the programm does run but I have to input the number multiple times. If I do run the code on another machine, it runs smothly with just the first input.
Here’s an example but it is the same, no matter what loop I choose.
<code> while (input != 1 || getchar() != 'n') {
while ((c = getchar()) != 'n' && c != EOF) { }
input = scanf ("%d", &number);
if (input != 1 || getchar() != 'n') {
printf ("Try again!n");
}
}
</code>
<code> while (input != 1 || getchar() != 'n') {
while ((c = getchar()) != 'n' && c != EOF) { }
input = scanf ("%d", &number);
if (input != 1 || getchar() != 'n') {
printf ("Try again!n");
}
}
</code>
while (input != 1 || getchar() != 'n') {
while ((c = getchar()) != 'n' && c != EOF) { }
input = scanf ("%d", &number);
if (input != 1 || getchar() != 'n') {
printf ("Try again!n");
}
}
Changed the structure of the code and changed the loop conditions and the loop-body, but still multiple times input or one run.
New contributor
Nemu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.