Thread: Calculator Issue (2293584)

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    26

    Calculator Issue (2293584)

    Hi guys,
    Thanks for the help with my first issue now I have on that I cant even see the logic behind.
    Im attempting to add two numbers and no matter what numbers I put in the answers 2293584.

    Heres the code

    Code:
    #include <stdio.h>
    
    int main()
    {
        int x, b,;
        printf ("Enter a Number");
        scanf ("%d", &x);
        printf ("Enter another number");
        scanf ("%d", &b);
        x = x + b;
        printf ("The answer is %d", &b);
        getchar();
        getchar();
        return 0;
    }
    Thanks in advance,

    is 2293584 2^ something which is why I keep getting it?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    You actually want:
    Code:
    printf ("The answer is &#37;d", x);
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    >> printf ("The answer is &#37;d", &b);
    You're printing the address of 'b' - not the value of 'x'.

    Copy and Paste strikes again!

    gg

Popular pages Recent additions subscribe to a feed