You're supposed to mind read him.
BTW, this code never executes:
Code:else printf("Invalid input!\tEnter selection (c, d, w, or q): ");
You're supposed to mind read him.
BTW, this code never executes:
Code:else printf("Invalid input!\tEnter selection (c, d, w, or q): ");
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
It is supposed to show you that you alwais get TWO characters. First time the desired one and an additional 0x0a for the newline that's still in the buffer from the previous call to scanf.
Kurt
So, you should clear the keyboard buffer:
Code:int c; while((c = getchar()) != '\n' && c != EOF);
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
No mind reading required.Originally Posted by dwks
I was just tired to repeat again that scanf leaves newlines in the buffer.
Kurt
Still don't get it. Maybe you can give me a link to a tutorial where I can read about this stuff in more details. Thanks
In your case there would be a simple solution
You could just as well put dwks code after each scanf in the program.Code:while((trans = getTrans()) != 'q') { if (trans == 'c' || trans == 'C'){ updateCheque(&balance, &cheque, &cheques, &bounced); transMenu(); } else if(trans == 'd' || trans == 'D'){ updateDeposit(&balance, &deposit, &deposits); transMenu(); } else if(trans == 'w' || trans == 'W'){ updateWithdrawal(&balance, &withdrawal, &withdrawals); transMenu(); } else if(trans == '\n'){ // just ignore newlines } else printf("Invalid selection, enter 'c', 'd', 'w', or 'q': "); }
Kurt
Zuk
Thanks, it works.