Thread: Variables problem

  1. #1
    Registered User
    Join Date
    Sep 2008
    Posts
    43

    Variables problem

    i have some sort of problem with my Variables. im using Dev-C++

    Code:
    #include <stdio.h>
    int main(void)
    {
        int x;
        int y;
        int z;
    
        x=6;
        y=4;
        z=x-y;
    
        printf("%d\n"),z;
    
        system("pause");
        return 0;
    }
    when i do this i get 4012464 no matter what i set my numbers to. i'm pretty sure that's wrong. its very possible im making a nube mistake. plz help me. =(

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Look at where your ) and , are.

    Then add these flags to the compiler settings
    -W -Wall -ansi -pedantic -O2

    With any luck, you'll be told that the printf string has too few parameters.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Sep 2008
    Posts
    43
    what?
    do u mean i have my , and ) backwards?
    and what was the compiler option thing. i couldn't find it on my program.

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Yes, you do. Sort of. You're passing the value of "z" to printf(), so it has to be inside printf()'s parentheses.

    In Dev-C++, I believe you go to Tools->Compiler Options. Then add what Salem suggested into the "extra compiler options" textbox. (It might be in a different tab, I can't remember.)
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  5. #5
    Registered User
    Join Date
    Sep 2008
    Posts
    43
    yay! the programs works.
    now i can finish the bigger program i was doing before i ran in to this problem.

  6. #6
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    Hello World? (Sorry, couldn't resist).
    Mainframe assembler programmer by trade. C coder when I can.

  7. #7
    Registered User
    Join Date
    Sep 2008
    Posts
    43
    ...i was doing the same thing with the scanf() function

  8. #8
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Did you manage to enable compiler warnings? If you have a reasonably recent version of Dev-C++ (4.9.x.x would be good enough), it should tell you when you make mistakes like that.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  9. #9
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    I think on Dev C++ 4.9.(whatever build they are on these days) you can simply mark a check box to enable these options as well.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. esbo's data sharing example
    By esbo in forum C Programming
    Replies: 49
    Last Post: 01-08-2008, 11:07 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Input File HELP, weird problem
    By gravity-1 in forum C++ Programming
    Replies: 5
    Last Post: 03-29-2005, 08:43 PM
  4. Replies: 6
    Last Post: 03-06-2005, 02:43 PM
  5. Replies: 4
    Last Post: 10-17-2002, 10:09 PM