I tried writing a simple calculator in C, cause Im a real beginner. (noob) Well the issue I have is that it does not allow me to input the operator character and just skips that piece of input and ends the program.
I tried writing a simple calculator in C, cause Im a real beginner. (noob) Well the issue I have is that it does not allow me to input the operator character and just skips that piece of input and ends the program.
Well, for one thing it's completely out of focus...
Post your actual code using the [code] and [/code] tags the forum provides...
I can't even read that blurry mess...
We normally use code tags here. Please read the Posting Code Announcement.
Your problem is because you have trailing newline characters in your input buffer from hitting the enter key. To get scanf to ignore these whitespace characters, use:
Notice the space in front of the format string.Code:scanf(" %c", &z);
Enter-key is a perfectly good character, so when you try to read in a character, guess what character you read in? You should use the ever-popular
for all your non-enter-key-reading needs.Code:scanf(" %c", &z);
Wow... you guys must have much better eyes than I do!