Getting Error: Called Object is not a Function

This is a discussion on Getting Error: Called Object is not a Function within the C Programming forums, part of the General Programming Boards category; Hello All, This is just a simple programming challenging from a book I'm using to learn C, it doesn't call ...

  1. #1
    Registered User
    Join Date
    Jun 2010
    Posts
    2

    Unhappy Getting Error: Called Object is not a Function

    Hello All,

    This is just a simple programming challenging from a book I'm using to learn C, it doesn't call for the if/else statement but I wanted to add it. I have used if/else before successfully, but for some reason now on the else portion it wont do the calculation. At first I thought celsius was a reserved word and thats why it was failing, but so I changed the variables name but still same error.

    Code:
    #include <stdio.h>
    
    int
    main(void)
    {
        int Choice; /* stores users choice on conversion */
        double fahrenheit; /* stores the temp in Fahrenheit */
        double centigrade; /* stores the temp in Celsius */
     
        /* Asks the user what they want to convert. */
        printf("Please choose how you want to convert\n");
        printf("Press 1 for Celsius to Fahrenheit\n");
        printf("Press 2 for Fahrenheit to Celsius: ");
        scanf("%d", &Choice);
    
        /*Determines what the user chooses */
        if (Choice == 1)
        {
            /* Obtains the temp and converts to fahrenheit */
            printf("\nPlease enter in the Temp in degree's Celsius: ");
            scanf("%lf", &centigrade);
    
            fahrenheit = (9/5 * centigrade)+32;
    
            printf("\n %.2f Celsius is %.2f Fahrenheit\n ", centigrade, fahrenheit);
        }
        else
        {
            /* Obtains the temp and converts to Celsius */
            printf("\nPlease enter in the Temp in degree's Fahrenheit: ");
            scanf("%lf", &fahrenheit);
    
            centigrade = (5/9)(fahrenheit - 32);
    
            printf("\n %.2f Fahrenheit is %.2f Celsius\n", fahrenheit, centigrade);
    
            
        }
          
    
            return(0);
    
    }
    when compiled I get this error ConvertTemp.c:40: error: called object is not a function and line 40 is centigrade = (5/9)(fahrenheit -32); but the equation in the if statement runs fine, and if I take else out completely it runs fine. I read around about people with similar errors, and tried to use the fixes they had but most were when they were actually calling a function aside from stdio.h I'm not calling any others. Thanks in advance.

  2. #2
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314
    Code:
            centigrade = (5/9)(fahrenheit - 32);
    Simple, You forgot * multiplication operator!
    Wait, 5/9 will evaluate to zero! Use 5.0/9.0.
    c-faq
    Last edited by Bayint Naung; 06-22-2010 at 09:53 PM.

  3. #3
    Registered User
    Join Date
    Jun 2010
    Posts
    2
    Thanks so much, I was thinking that ()() would be multiplication like in algebra. I will make a note of that in the future, always have to use the operators.

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,902
    centigrade = (5.0/9)*(fahrenheit - 32);
    Works fine to. The standard specifies that when you perform arithmetic on two variables, they are converted to the same size first--the biggest size (and integers are promoted to floating point, too). Therefore, the result is a floating point temporary.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 09:18 PM
  2. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 04:06 PM
  3. Passing A Function From One Object to Another
    By HalNineThousand in forum C++ Programming
    Replies: 8
    Last Post: 03-28-2008, 08:26 PM
  4. dllimport function not allowed
    By steve1_rm in forum C++ Programming
    Replies: 5
    Last Post: 03-11-2008, 04:33 AM
  5. Function doesn't return an object
    By Aiwendil in forum C++ Programming
    Replies: 2
    Last Post: 04-10-2004, 04:15 PM

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