Thread: help me solve/understand this conflicting types error

  1. #1
    Registered User
    Join Date
    Aug 2008
    Posts
    4

    Question help me solve/understand this conflicting types error

    When I try to compile this:

    Code:
    /* Exercise 1.15. Rewrite the temperature conversion program of Section 1.2 to use a function for conversion. */
    
    /* C = (5 / 9)(F - 32) */
    
    #include <stdio.h>
    
    main()
    {
     int fahr;
    
     printf("\n\nfahrenheit\tcelsius\n");
     for(fahr = 0; fahr <= 300; fahr = fahr + 20)
    	printf("%3d\t\t%3.0f\n",fahr,fahr_cel(fahr));
     printf("\n\n");
    
     return 0;
    }
    
    
    float fahr_cel(int fahr)
    {
     float cels;
    
     cels = (5.0 / 9.0) * (fahr - 32.0);
    
     return cels;
    }
    I get this from the compiler:
    Code:
    exercise 1-15.c: In function ‘main’:
    exercise 1-15.c:13: warning: format ‘%3.0f’ expects type ‘double’, but argument 3 has type ‘int’
    exercise 1-15.c: At top level:
    exercise 1-15.c:20: error: conflicting types for ‘fahr_cel’
    exercise 1-15.c:13: error: previous implicit declaration of ‘fahr_cel’ was here
    But I can't find what's wrong with the code. Why does the argument 3 has type int instead of float??

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    You can't call a function without a prototype. (Well, you can try, but you get what you got.) So put a function prototype at the top of your file.

  3. #3
    Registered User
    Join Date
    Aug 2008
    Posts
    4
    thanks! (so dumb)

  4. #4
    a newbie :p
    Join Date
    Aug 2008
    Location
    Zurich, Switzerland, Switzerland
    Posts
    91
    just put main() below...
    so you don't have to put prototype...

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > so you don't have to put prototype...
    Which is a very short-sighted view. When you get to multi-file projects, they're essential.
    Besides, a list of prototypes at the start of the module is useful information for the reader.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

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, 08:18 PM
  2. How to monitor process creation?
    By markiz in forum Windows Programming
    Replies: 31
    Last Post: 03-17-2008, 02:39 PM
  3. more then 100errors in header
    By hallo007 in forum Windows Programming
    Replies: 20
    Last Post: 05-13-2007, 08:26 AM
  4. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 05:45 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM