type conversion

This is a discussion on type conversion within the C Programming forums, part of the General Programming Boards category; Hi! I have problem with type conversion. when I compile the program I get this error: ( 'count' : redefinition; ...

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    16

    type conversion

    Hi!
    I have problem with type conversion.
    when I compile the program I get this error:
    ( 'count' : redefinition; different basic types ).
    please tell me about type conversion.

    Code:
    #include<stdio.h>
    int count(double houre, double charge);
    int main(){
         double h=4;
        double c=2;
    
        printf("%\n", count(h,c));
        return 0;
    }
    int count(double houre, double charge){
        double value;
    	 if(houre<=3.0)
                     {
    	    return charge;
                     }
    	   else 
    	 {
    	value=(2+(0.5*(houre-3)));
    	       return value;
    	 }
      return 0;	
    }

  2. #2
    Just kidding.... fnoyan's Avatar
    Join Date
    Jun 2003
    Location
    Still in the egg
    Posts
    269
    Hi

    I get no error while compiling the source! But, i add a "d" into your printf() statement. Program works!

    printf("%d\n", count(h,c));

    I am using : Slackware linux 10.0 , gcc version 3.3.4

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,751
    I just get
    $ gcc -W -Wall foo.c
    foo.c: In function ‘main’:
    foo.c:7: warning: unknown conversion type character 0xa in format
    foo.c:7: warning: too many arguments for format
    But that's just the broken printf() call - nothing to do with count
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    I think the only thing wrong with that, as everyone is saying, is this line:
    Code:
        printf("%\n", count(h,c));
    it should be
    Code:
        printf("%d", count(h,c));
    or
    Code:
        printf("%i", count(h,c));
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can you check what is wrong with this code
    By Ron in forum C++ Programming
    Replies: 4
    Last Post: 08-01-2008, 11:59 PM
  2. Question on l-values.
    By Hulag in forum C++ Programming
    Replies: 6
    Last Post: 10-13-2005, 05:33 PM
  3. ras.h errors
    By Trent_Easton in forum Windows Programming
    Replies: 8
    Last Post: 07-15-2005, 11:52 PM
  4. Windows using Dev-C++
    By Renegade in forum C++ Programming
    Replies: 15
    Last Post: 07-07-2005, 09:29 PM
  5. overloaded operator for type conversion error
    By mangoMan in forum C++ Programming
    Replies: 1
    Last Post: 03-10-2004, 08:38 PM

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