Thread: type conversion

  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
    275
    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 int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    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.

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    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, 10:59 PM
  2. Question on l-values.
    By Hulag in forum C++ Programming
    Replies: 6
    Last Post: 10-13-2005, 04:33 PM
  3. ras.h errors
    By Trent_Easton in forum Windows Programming
    Replies: 8
    Last Post: 07-15-2005, 10:52 PM
  4. Windows using Dev-C++
    By Renegade in forum C++ Programming
    Replies: 15
    Last Post: 07-07-2005, 08: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