Thread: Just starting out, this program will compile but freezes when run?

  1. #1
    Registered User
    Join Date
    May 2015
    Posts
    2

    Just starting out, this program will compile but freezes when run?

    Hi, I am very new to programming and have written a very simple program to convert inches to mm and spit out the results. This program compiles just fine (running OpenSUSE through Oracle VirtualBox) but when I run it, nothing ever happens and it never finishes (ie it seems to have frozen). Again, I am extremely new to this, so forgive me for any mistakes, but here is the program:

    Code:
    #include <stdio.h>
    
    #define MAX 100
    #define STEP 10
    #define CONVERSION 25.4
    
    main()
    {
      float inch, mm;
      inch=0;
      while (inch<=MAX);
         {
         mm=inch*CONVERSION;
         printf ("%f\t %f\n", inch, mm);
         inch=inch+STEP;
         }
      return 0;
    }

  2. #2
    Registered User
    Join Date
    Mar 2010
    Posts
    582
    Code:
    while (inch<=MAX);
    Look. Look closely.... There's a semicolon there when there shouldn't be. This means:

    Code:
    while (inch<=MAX)
           ;     // do nothing
    <some more code that won't get run.....>

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    4,485
    You seem to have an errant semicolon after your while statement.


    Jim

  4. #4
    Registered User
    Join Date
    May 2015
    Posts
    2
    Quote Originally Posted by smokeyangel View Post
    Code:
    while (inch<=MAX);
    Look. Look closely.... There's a semicolon there when there shouldn't be. This means:

    Code:
    while (inch<=MAX)
           ;     // do nothing
    <some more code that won't get run.....>

    Thanks!!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help on Starting a Program!
    By Sharpenel in forum C Programming
    Replies: 3
    Last Post: 10-22-2012, 03:06 AM
  2. C - Program freezes; futex_wait_queue_me
    By youjustreadthis in forum C Programming
    Replies: 0
    Last Post: 08-22-2012, 09:49 AM
  3. Simple strcmp program freezes upon scanf
    By drbr0wn in forum C Programming
    Replies: 6
    Last Post: 01-17-2012, 12:28 PM
  4. program freezes - structure searching.
    By Vber in forum C Programming
    Replies: 9
    Last Post: 03-20-2003, 09:35 AM

Tags for this Thread