teacher is looping my while-switch by inputing a char.

Pages: 12
so the results are how many times items were successfully read. and the only reason it is unable to read the letter is because of the format specifier?
What does the documentation say it returns? What does it return in your program?

Read the documentation that both firedraco and I pointed you to (and that you failed to comprehend) and ask yourself "is scanf() going to be able to successfully convert the letter my teacher just entered to the integer I asked it to input?" The answer to that question should tell you what scanf() returns.
but thats what im saying i DONT want it to convert the letter to a number. my program ask's for a number input not a letter input. my teacher is putting in a letter to send it on a infinite loop. in other words she is trying to mess the program up somehow i know %d is for numbers and i know that %s is for letters but how do i stop the infinite loop when she enters a letter(which isnt surposed to be in there)
In my example code, tell me exactly what the contents of "result" and "item" are after:

A) entering "1"

and

B) entering "A"

And then tell me what you think you can do with that information.
but mine is in a while with a switch statment so when one is entered in mine it goes to the 1st case but if a is entered it goes on a infinite loop. how can i stop the loop?
You must answer my question (correctly) before I answer yours.
ok with your program it will execute whatever is in the if statement when "1" is put in


if you put "A" in then it doesnt execute what is in the if
The correct answer to my question is in the form of
result = x
item = y

I did not ask what it does.
ok so result = x and item = y. keep explaining please
Ugh. After his code executes, what is result equal to, and item equal to, if he inputs 1? And, separately, what is result equal to, and item equal to, if he inputs the letter A? Run it through a debugger or something and see, or use the reference section of this site as has been suggested.
oh man. i just tried it. checking for error isn't enough. the buffer has to be flushed somehow.
Topic archived. No new replies allowed.
Pages: 12