Thread: Bug in the addition drill program

  1. #1
    Registered User
    Join Date
    Aug 2010
    Location
    Dhaka, Bangladesh
    Posts
    16

    Bug in the addition drill program

    Hi,
    There is a bug in this addition drill program that I can't fix up. I can't input Y/N characters in this program. Is there anyone who can help me to fix it up?


    Code:
    #include <conio.h>
    #include <stdio.h>
    
    main()
    {
     int answer, count;
     int ch;
     ch = getche();
    
     for(count=1; count<11; count++) {
      printf("What is %d + %d? ", count, count);
      scanf("%d", &answer);
      if(answer == count + count) printf("Right!\n");
      else{
       printf("Sorry, you're wrong\n");
       printf("Would you like to try again? Y/N: \n");
       scanf("%c", &ch);
    
       if(ch=='Y') {
        printf("\nWhat is %d + %d? ", count, count);
        scanf("%d", &answer);
        if(answer == count+count) printf("Right!\n");
        else
         printf("Wrong, the answer is %d\n", count+count);
        }
    
       else
        printf("The answer is %d\n", count+count);
       }
      }
      return 0;
     }

    Thanks in advance

  2. #2
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314
    Please read this:fflush vs gets

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Slot Machine program c++ bug
    By nobo707 in forum C++ Programming
    Replies: 12
    Last Post: 09-23-2009, 07:29 PM
  2. Disappearing Bug
    By el-sid in forum C++ Programming
    Replies: 4
    Last Post: 08-16-2009, 12:12 PM
  3. Bug favour needed re: C++ Program
    By Nicole in forum C++ Programming
    Replies: 2
    Last Post: 12-05-2001, 07:13 AM
  4. Repetitive Bug with C++ Program - Needs Help
    By kuphryn in forum C++ Programming
    Replies: 5
    Last Post: 11-15-2001, 08:07 PM
  5. Bug in Program - please help!
    By muffin in forum C Programming
    Replies: 4
    Last Post: 08-31-2001, 09:33 AM

Tags for this Thread