Thread: Code with two functions just wont return the correct result

  1. #1
    Registered User
    Join Date
    Sep 2013
    Location
    Jamaica
    Posts
    134

    Code with two functions just wont return the correct result

    Each time I run it I get in correct result. I even tried running with code from from my book and it failed aswell. The code from the tutorial worked some how. BTW I use DevC++ as my compiler.

    Code:
    /*
                    Fail results
                    Fail results
                    Fail results
    */
    #include <stdio.h>
    
    
    int addition(int x, int y);
    
    
    int main()
    {
        int x;
        int y;
        
        printf("\t\tThis progam will take any two numbers and ADD them.\n");
        fflush(stdout);
        printf("Enter a number. NO decimals please.\n");
        scanf("%d", &x);
        fflush(stdin);
        printf("Enter a second number.\n");
        scanf("$d", &y);
        fflush(stdin);
        
        //results
        printf("The result is: %d.\n", addition(x, y));
        getchar();    
    }
    int addition(int x, int y)
    {
        return x + y;
    }

  2. #2
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    Get rid of the fflush's. You don't need them. And fflush(stdin) is undefined in standard C (although it works on Windows).
    And you're using a $ instead of the proper % in the second scanf.
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  3. #3
    Registered User
    Join Date
    Sep 2013
    Location
    Jamaica
    Posts
    134
    OMG thank you.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. It doesn't return a correct result...
    By pantera in forum C++ Programming
    Replies: 5
    Last Post: 01-16-2010, 05:23 PM
  2. Correct algorithm, wrong result (cout problem?)
    By dember in forum C++ Programming
    Replies: 6
    Last Post: 11-02-2009, 06:03 PM
  3. Return value: Error or result?
    By Cactus_Hugger in forum C Programming
    Replies: 3
    Last Post: 05-03-2007, 12:23 AM
  4. Correct way to return arrays from functions
    By bodydrop in forum C Programming
    Replies: 7
    Last Post: 04-30-2006, 11:53 AM
  5. Pass values to C++ dll and return result
    By joeyzt in forum C++ Programming
    Replies: 2
    Last Post: 06-21-2004, 11:26 PM