title: How to fix "return 0 / exit(0) not working properly inside for loop"?
body: <p>I was making a scientific calculator. And thought of looping the statements until the user asks to stop by using 0 as one of the options. But even after entering 0. It asks one last time this statement:
  <code>printf("Enter two numbers (For only one no. required you can just enter other number anything)\n");</code></p>
  
  <p>I have tried using <code>goto, exit(0)</code> and <code>return</code> 0 statements. Even <code>while(1)</code> and <code>for(;;)</code> loop also.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include&lt;math.h&gt;
  int main()
  {
      int a;
      float b,c;
      float d=3.14159/180;
      while(1)
      {
      printf("\nScientific Calculator :\n");
      printf("Enter option:\n 0- Exit, 1-Add, 2-Sub, 3-Multiply, 4-Divide,\n 5-sin(x), 6-cos(x), 7-tan(x), 8-sinh(x), 9-cosh(x), 10-tanh(x),\n11-log10(x),12-exponent,13-power of x w.r.t y \n");
      scanf("%d",&amp;a);
      printf("Enter two numbers (For only one no. required you can just enter other number anything)\n"); //Here is where it starts even after return 0
      scanf("%f%f",&amp;b,&amp;c); //Here after inputting value it ends.
      switch(a)
      {
          case 0:return 0; //Here is the return 0;
          case 1:printf("%d",(int)(b+c)); break;
          case 2:printf("%d",(int)(b-c)); break;
          case 3:printf("%d",(int)(b*c)); break;
          case 4:printf("%f",b/c); break;
          case 5:printf("%f",sin(b*d)); break;
          case 6:printf("%f",cos(b*d)); break;
          case 7:printf("%f",tan(b*d)); break;
          case 8:printf("%f",sinh(b*d)); break;
          case 9:printf("%f",cosh(b*d)); break;
          case 10:printf("%f",cosh(b*d)); break;
          case 11:printf("%f",tanh(b*d)); break;
          case 12:printf("%f",log10(b)); break;
          case 13:printf("%f",exp(b)); break;
          case 14:printf("%f",pow(b,c)); break;
          default:printf("Enter correct option\n");
      }
      }
      return 0;
  
  }
  </code></pre>
  
  <p>I wanted it to just exit and come out of the program but it is asking input <code>printf("Enter two numbers ---\n");</code> and after inputting values it exits.</p>