Is this right

This is a discussion on Is this right within the C Programming forums, part of the General Programming Boards category; I'm using the Miracle C compiler with windows XP and when I go to compile this: Code: #include <stdio.h> int ...

  1. #1
    Registered User
    Join Date
    Aug 2002
    Posts
    109

    Is this right

    I'm using the Miracle C compiler with windows XP and when I go to compile this:

    Code:
    #include <stdio.h>
    
    int main()
    {
        float a;
        a = 0;
        while (a <= 100)
        {
            printf("%6.2f degrees F = %6.2f degrees C\n",
                a, (a - 32.0) * 5.0 / 9.0);
            a = a + 10;
        }
        fgetc(stdin);
        return 0;
    }
    Miracle C says back to me:

    Miracle C Compiler (r3.2), written by bts.
    Compiling C:\Documents and Settings\Daniel Granger\My Documents\C\f2c.c
    main

    C:\Documents and Settings\Daniel Granger\My Documents\C\f2c.c: line 7: unrecognised types in comparison
    'while (a <= 100) { printf("%6.2f degrees F = %6.2f degrees C\n", a, (a - 32.0) * 5.0 / 9.0)'
    aborting compile

    Can some please tell me whats going wrong

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    It's just like it says:

    while (a <= 100)

    You cannot compare an integer and a floating point number like that. Do the following:

    while( (int)a <= 100 )

    That'd be your best option.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Green Member Cshot's Avatar
    Join Date
    Jun 2002
    Posts
    892
    It runs perfectly fine on mine. (MS VC++ 6.0)

    Output:
    0.00 degrees F = -17.78 degrees C
    10.00 degrees F = -12.22 degrees C
    20.00 degrees F = -6.67 degrees C
    30.00 degrees F = -1.11 degrees C
    40.00 degrees F = 4.44 degrees C
    50.00 degrees F = 10.00 degrees C
    60.00 degrees F = 15.56 degrees C
    70.00 degrees F = 21.11 degrees C
    80.00 degrees F = 26.67 degrees C
    90.00 degrees F = 32.22 degrees C
    100.00 degrees F = 37.78 degrees C
    Perhaps it doesn't like comparing a float to an int. Try casting it or comparing with 100.0
    Try not.
    Do or do not.
    There is no try.

    - Master Yoda

  4. #4
    GSLR
    Guest
    while( a <= 100.0 )

    Might Help ?

    Q

  5. #5
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Originally posted by GSLR
    while( a <= 100.0 )

    Might Help ?

    Q
    More like

    while( a <= 100.0f )
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  6. #6
    Patent Pending GSLR's Avatar
    Join Date
    Sep 2001
    Posts
    134
    Oops!! Missed That
    And To All Those Opposed, WELL !!!
    >Deleted< " Looks like a serial no."

  7. #7
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Originally posted by GSLR
    Oops!! Missed That
    Hey, no big deal.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21