Debugging code in C

前端 未结 1 1399
独厮守ぢ
独厮守ぢ 2021-01-27 05:49

Can someone tell me what is wrong with my code and why it is producing this output.

Code:

int main(){
  unsigned num;
  char response;

do{
 printf(\"Ple         


        
相关标签:
1条回答
  • 2021-01-27 06:19

    When you ask whether you want to repeat, you only read the y, leaving the es queued up in stdin. When you go to read the next number, scanf tries to parse that as a number, fails, and returns without altering num. When you prompt the user, you need to burn that whole line.

    0 讨论(0)
提交回复
热议问题