title: C Programming help - Option for user to exit program
body: <p>this is a follow on question from one I asked recently: </p>
  
  <p><a href="https://stackoverflow.com/questions/22391308/c-programming-help-providing-user-with-option-to-exit-a-program">C Programming help - providing user with option to exit a program</a></p>
  
  <p>I now have a new problem.  I can get the program to exit if a user enters any letter which is great, but now if a number is entered nothing happens. The while loop doesn't seem to run.. </p>
  
  <p>Can you please have a look at my code and see if you can spot what's wrong, thanks.  Also, ideally i'd like xterm's window to close if the user wishes to exit. I'd be greatful if anyone could show me how to do this.  Anyway here's the code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main()
  {
       float number;
       float sum = 0;
  
  
       printf ("Please enter number or enter any letter to exit:\n");
       scanf ("%f", &amp;number);
  
       // if user ENTERS a letter, program will terminate
  
       if(1!=scanf ("%f", &amp;number))
       {
          getchar();
          printf ("Exiting the program...\n");
          exit(0);
       }
  
  
       while (1)
       {
          sum += number;
          printf ("Sum: %.2f\n", sum);
          printf ("Please enter number or enter any letter to exit:\n");
          scanf ("%f", &amp;number);
  
          // if user ENTERS a letter, program will terminate
  
               if(1!=scanf ("%f", &amp;number))
               {
                  getchar();
                  printf ("Exiting the program...\n");
                  exit(0);
               }
  
       }
  
      return 0;
  }
  </code></pre>