Whats wrong in my code?

This is a discussion on Whats wrong in my code? within the C Programming forums, part of the General Programming Boards category; Implement the following two functions /* returns Celsius equivalent of a Fahrenheit temperature (ft) */ double celsius(double ft); this part ...

  1. #1
    Registered User
    Join Date
    Sep 2008
    Posts
    37

    Question Whats wrong in my code?

    Implement the following two functions
    /* returns Celsius equivalent of a Fahrenheit temperature (ft) */
    double celsius(double ft); this part doesn't want to work check code please.

    /* returns Fahrenheit equivalent of a Celsius temperature (ct) */
    double fahrenheit (double ct); this part Done and works


    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    
    double f2c(int f);
    double c2f(int i);
    
    int main ( void )
    {
        int i, f;
        double Celsius, Fahrenheit;
    
        printf("\n\t Celsius<->Fahrenheit\n\n\n");
    
        for ( i = 0; i <= 100; i += 2)
        {
            Fahrenheit = c2f(i);
    
            printf ( "\t%3d \t - %6.2f \n",  i, Fahrenheit);
        }
    
        printf("\n\tFahrenheit<->Celsius \n");
         for ( f = 32; f <= 212; f += 4) {
             
                Celsius = f2c(f);
                
            printf ( "\t%3d  \t - %6.2f \n",  f, Celsius);
                
         }
                
        system("pause");
    }
    
    /*Implementation Fahrenheit to Celsius*/ 
    
    double f2c(int f)
    {
      return (5.0 / 9.0) * (f - 32.0);
    }
    
    /*Implementation Celsius to Fahrenheit*/ /* NOT Working*/ 
    /*What Exactly I need to change Here*/
    
    double c2f(int i)
    
           return (9.0 / 5.0) * i) + 32;
    {
           
    }
    Don't assume i know exactly what i have to change that's why I'm asking, I'm begineer and I'm just learning C. If i have anymore errors please let me know where to correct it. Thanks

    [B]Errors I Get:[/B]

    In function `double c2f(int)':
    40 expected identifier before '(' token
    40 named return values are no longer supported

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Put the return for c2f inside the curly braces.

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,293
    Also, does anything look a little "mismatched" here:
    Code:
           return (9.0 / 5.0) * i) + 32;
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  4. #4
    Registered User
    Join Date
    Sep 2008
    Posts
    37
    Quote Originally Posted by Adak View Post
    Put the return for c2f inside the curly braces.
    I already did that and still gives me the same errors. i know is a very small error and I already tried days to get this far in this complicated code for me; easy for you and if you would show me how to do it I'll appreciated, If i see it i will learn better not to do that error again.

  5. #5
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    All I did was change c2f to look like this, and now the program compiles and works without error:
    Code:
    double c2f(int i)
            {
    
           return (9.0 / 5.0) * i + 32; 
              
    }
    so it has braces in the right place, and no extra ) after i (the compiler will make that a smiley face

    You should be using a text editor with syntax highlighting for C that will point out simple things like extra unclosed braces.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  6. #6
    Registered User
    Join Date
    Sep 2008
    Posts
    37
    Quote Originally Posted by MK27 View Post
    All I did was change c2f to look like this, and now the program compiles and works without error:
    Code:
    double c2f(int i)
            {
    
           return (9.0 / 5.0) * i + 32; 
              
    }
    so it has braces in the right place, and no extra ) after i (the compiler will make that a smiley face

    You should be using a text editor with syntax highlighting for C that will point out simple things like extra unclosed braces.

    Thanks a lot, it really helped me.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. what is wrong in this simple code
    By vikingcarioca in forum C Programming
    Replies: 4
    Last Post: 04-23-2009, 07:10 AM
  2. what is wrong with this code please
    By korbitz in forum Windows Programming
    Replies: 3
    Last Post: 03-05-2004, 09:11 AM
  3. I cant find what is wrong with this code
    By senegene in forum C Programming
    Replies: 1
    Last Post: 11-12-2002, 05:32 PM
  4. Anyone see what is wrong with this code?
    By Wise1 in forum C Programming
    Replies: 2
    Last Post: 02-13-2002, 01:01 PM
  5. very simple code, please check to see whats wrong
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 10-10-2001, 12:51 AM

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