title: Simple Calculator and while loop
body: <p>Hi I am wrinting a simple calulator using while(true) and its working except that, when the loop ends and begins again, it repeats the first line twice, does anyone have a solution for this ? thanks in advance ...</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main()
  {
  char a,ch;
  int x,y,i,n,e,s;
  while(1) {
      printf("\nEnter the operation:");
      scanf("%c",&amp;a);
      e=a;
      if (e=='+') {
          printf("\nEnter the first integer:");
          scanf("%d",&amp;x);
          printf("\nEnter the second integer:");
          scanf("%d",&amp;y);
          s=x+y;
          printf("\nThe result of %d+%d is:%d\n",x,y,s);
      } else {
          if (e=='-') {
          printf("\nEnter the first integer:");
          scanf("%d",&amp;x);
          printf("\nEnter the second integer:");
          scanf("%d",&amp;y);
          s=x-y;
          printf("\nThe result of %d-%d is:%d\n",x,y,s);
      } else {
          if (e=='*') {
          printf("\nEnter the first integer:");
          scanf("%d",&amp;x);
          printf("\nEnter the second integer:");
          scanf("%d",&amp;y);
          s=x*y;
          printf("\nThe result of %dx%d is:%d\n",x,y,s);
      } else {
          if (e=='/') {
          printf("\nEnter the first integer:");
          scanf("%d",&amp;x);
          printf("\nEnter the second integer:");
          scanf("%d",&amp;y);
          s=x/y;
          printf("\nThe result of %d/%d is:%d\n",x,y,s);
      } else {
          if (e=='%') {
          printf("\nEnter the first integer:");
          scanf("%d",&amp;x);
          printf("\nEnter the second integer:");
          scanf("%d",&amp;y);
          s=x%y;
          printf("\nThe result of %d%%d is:%d\n",x,y,s);
      } else {
          if (e=='^') {
          printf("\nEnter the first integer:");
          scanf("%d",&amp;x);
          printf("\nEnter the second integer:");
          scanf("%d",&amp;y);
          s=pow(x,y);
          printf("\nThe result of %d^%d is:%d\n",x,y,s);
      }}}}}}
  }}
  </code></pre>