Question about adding in C

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cswisher
    New Member
    • Mar 2013
    • 2

    Question about adding in C

    I am new to C and thought that I would just try out doing some simple adding. Whenever I run it the answer is 0. I was wondering what I was doing wrong. Here is the code:

    Code:
    #include <stdio.h>
    main()
    {
    float ans;
    ans=1+1;
    printf(" %d", ans);
    }
    Any and all help appreciated.
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    In your printf, use %f to display a float. A %d tells printf that your data is an int, which it's not, so your display is not what you expect.
    Last edited by weaknessforcats; Mar 8 '13, 02:21 AM. Reason: typo

    Comment

    • cswisher
      New Member
      • Mar 2013
      • 2

      #3
      Oh dang. I am an idiot. Thank you.

      Comment

      Working...