Thread: so how do I fix this or what did i do rong

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

    so how do I fix this or what did i do rong

    hay guys shat is happining here I dont understand
    here is the code
    Code:
    int main(int x = 100, int y = 100)
    {
    cout << x << ", " << y << endl;
    cin.ignore();
    }
    i should get 100, 100 but i get this 1, 2242648

    so how do I fix this or what did i do rong
    I’m Dyslexic and I know that I don’t spell well so quit telling to learn my English because I do my best at it all right.

    Windows XP with Dev-C++ for now.

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I would say that's kinda undefined at best. Main isn't supported to take x and y. Why not make another function not named main and try again?

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    main has some prototypes that are legal, and others aren't. see the faq for more information.

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    And aside from the fact that you can't just use any arguments to main(), default arguments are based on the compiler resolving the call to the function [as discussed elsewhere]. In this case, that's the C runtime library, and you need to declare the main() with defaults there, then call main without arguemnts. Since NONE of the above is happening, x and y are just reflecting the values of argc and argv respectively.

    So it's not EVER going to work, unless you modify the code calling main - which you most likely don't actually want to do.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Nov 2007
    Posts
    43
    sorry not the right code here
    Code:
    #include <iostream>
    #include <stdlib.h>
    #include <windows.h>
    
    int click(int x, int y)
    {
      mouse_event(MOUSEEVENTF_LEFTDOWN, x, y, 0, 0);
      Sleep(rand(20)&#37;15);
      mouse_event(MOUSEEVENTF_LEFTUP, x, y, 0, 0);
    cout << x << "," << y << endl; // x = 100 and y = 100 like it is suposted to
    return 0;
    }
    
    int main()
    {
    int x, y;
    click(110, 100);
    cout << x << "," << y << endl; // x = 37879712 and y = 575 ????????????????????
    cin.ignore();
    }
    Why is x and y returning that value when nothing else was changed?
    I’m Dyslexic and I know that I don’t spell well so quit telling to learn my English because I do my best at it all right.

    Windows XP with Dev-C++ for now.

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    x and y are never initialized, so you're getting junk data.
    Do you use compiler warnings?

  7. #7
    Registered User
    Join Date
    Nov 2007
    Posts
    43
    yes but dosent show up for this than. could you show me an example of how this should be? thanks
    I’m Dyslexic and I know that I don’t spell well so quit telling to learn my English because I do my best at it all right.

    Windows XP with Dev-C++ for now.

  8. #8
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    How to enable warnings or junk data problem? You're being unclear.

  9. #9
    Registered User
    Join Date
    Nov 2007
    Posts
    43
    sorry the junk data
    I’m Dyslexic and I know that I don’t spell well so quit telling to learn my English because I do my best at it all right.

    Windows XP with Dev-C++ for now.

  10. #10
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Code:
    int x = 100, y = 100;

  11. #11
    Registered User
    Join Date
    Nov 2007
    Posts
    43
    sorry maybe I’m saying this wrong but what I’m trying to get to happen if for x and y to be initialized from the first function into the main function. So I’m wonting the main function to return 100 100 because function “click” declared x and y before.
    I’m Dyslexic and I know that I don’t spell well so quit telling to learn my English because I do my best at it all right.

    Windows XP with Dev-C++ for now.

  12. #12
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Erm, you want the click function to store information in x and y? If so, then read the references tutorial at the site.

  13. #13
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Those are different x and y.

    If you want x and y in main to "become" x and y in your function, you need to pass by reference, which in C++ means to use
    Code:
    int click(int &x, int &y)
    This means that "an alias" of x and y is passed, rather than a copy. Of course, if you take a copy of a page in a book, and scribble all over it, it will still be no scribbles in the book itself. Similarly, you need the original x and y to be in your function, not copies.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. compiling my code, i can't fix error
    By howru in forum C Programming
    Replies: 2
    Last Post: 04-22-2008, 03:38 AM
  3. C++ code need help to fix
    By McReal in forum C++ Programming
    Replies: 9
    Last Post: 05-12-2007, 02:48 PM
  4. Help me fix my mess!!!!
    By Starr in forum C++ Programming
    Replies: 35
    Last Post: 02-01-2006, 03:40 PM
  5. easy fix
    By sentienttoaster in forum C++ Programming
    Replies: 8
    Last Post: 11-30-2003, 11:03 PM