Im in the stages of creating my 1st few programs and i am stuck on this code,
i cant figure out how to test what the user types in to keep the loop going or not
if the user enters y then i want it to loop, and n to end the loop. can anyone help?
Im in the stages of creating my 1st few programs and i am stuck on this code,
i cant figure out how to test what the user types in to keep the loop going or not
if the user enters y then i want it to loop, and n to end the loop. can anyone help?
right or wrong, you should post whatever code you have been able to muster.
You can get one character of input using getchar(). Suppose you do:
you can then simply do:Code:int c; c = getchar();
Code:if(c == 'y) /* do something */ else if(c == 'n') /* do something else */
to improve it a little you can use the toupper function so you won't have to check for caps, i.e.
Either way the best way uncovering things in programming is: Try it! Mess it up! and try it again...Code:while (condition!='N'){ /*Whatever process*/ printf("Do you wan to continue? [Y/N]?\n"); condition=toupper(getchar()); /*Whatever the user enters will forcibly be a cap*/ }