Thread: Can't figure out what's wrong with this simple function

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    14

    Can't figure out what's wrong with this simple function

    It's for a school assignment. I have no clue what's going on, but it prints "1077936128" for friends_helped and "0" for coins_earned, despite the fact that the vars being received are 1 and 27, respectively.


    Code:
    void display_round_statistics(int round, double coins_earned, int friends_helped){
    
    	printf("\nRound %d Totals:\n\nFarm Coins earned: %d\n%d Friend",round, coins_earned, friends_helped);
    	if(friends_helped!=1) printf("s");
    	printf(" helped\n");
    
    }

    <I'm new here, so sorry if I've violated any protocols>

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Welcome to the forum, Yinyang!

    You're trying to print a double (coins_earned), as an int (%d), use %f instead.

    Then re-test.

  3. #3
    Registered User
    Join Date
    Nov 2010
    Posts
    14

    Thumbs up

    Thanks, Adak. I knew it would be something silly like that.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 05-13-2011, 08:28 AM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  4. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  5. Bisection Method function value at root incorrect
    By mr_glass in forum C Programming
    Replies: 3
    Last Post: 11-10-2005, 09:10 AM