0

I use emulated Turbo C++ IDE 3.0 for development in C. I get the above mentioned error on when I run the following program:

#include<stdio.h>
#include<conio.h>
main()
{
    int i,j,k;
    char x;
    do
    {
        printf("enter the number i: ");
        scanf("%d",&i );
        printf("enter the number j: ");
        scanf("%d",&j);
        k=i+j;
        printf("Addition of given numbers :%d ",k);
        printf("\n Do you to continue : ");
        scanf("%c",&x);
    } while(x=='y'||x=='Y');    
    getch();
}

It was successfully compiled without errors or warnings. At run time, the problem arises after the statement printf("\n Do you to continue : ");.

When I enter a value for this, the error shows up. I tried in dev C++ but the problem prevails. I am using Windows 7 Ultimate.

YasirA
  • 9,531
  • 2
  • 40
  • 61
user2234743
  • 1
  • 1
  • 1
  • 1
  • 1
    Please get yourself a better (or, at least, more modern) compiler than Turbo C! – Jonathan Leffler Apr 02 '13 at 06:34
  • What is the exact problem? – Alex Apr 02 '13 at 07:08
  • i suggest you use `fgets()` to read from keyboard instead to keep things as simple as possible. then you do not need to care whether there is a left over carriage return or an invalid character in the buffer. then just use `atoi()` to convert the string to integer. – AndersK Apr 02 '13 at 08:43

1 Answers1

0

Suggestion

change

scanf("%c",&x);

to

scanf(" %c",&x);

BLUEPIXY
  • 39,699
  • 7
  • 33
  • 70