Thread: How to return a double correctly?

  1. #1
    CIS and business major
    Join Date
    Aug 2002
    Posts
    287

    How to return a double correctly?

    Here is the code:
    Code:
    #include <stdio.h>
    
    main()
    {
        int integer_var = 100;
        float floating_var = 331.79;
        double double_var = 8.44e+11;
        char char_var = 'W';
    
        printf("integer_var = %i\n", integer_var);
        printf("floating_var = %f\n", floating_var);
        printf("double_var = e\n", double_var);
        printf("char_var = %c\n", char_var);
        return 0;
    }
    And it returns:

    integer_var = 100
    floating_var = 331.790009
    double_var = e
    char_var = W

    Why is the double not getting outputted correctly?

  2. #2
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Look again at the string and try to notice what is missing that you haven't missed in all others.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  3. #3
    CIS and business major
    Join Date
    Aug 2002
    Posts
    287
    %, thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Cast double to int correctly(5 lines of code)
    By tmac619619 in forum C Programming
    Replies: 3
    Last Post: 10-22-2012, 12:13 PM
  2. To return a double value
    By shruthi in forum C Programming
    Replies: 4
    Last Post: 09-12-2012, 10:52 AM
  3. pow() doesnt return a double?
    By FloatingPoint in forum C++ Programming
    Replies: 23
    Last Post: 08-04-2003, 11:11 AM
  4. WinSock and gethostbyname() won't return correctly...
    By SyntaxBubble in forum C++ Programming
    Replies: 2
    Last Post: 07-05-2002, 12:08 PM
  5. return as a double?
    By Dummies102 in forum C++ Programming
    Replies: 5
    Last Post: 02-22-2002, 08:25 PM

Tags for this Thread