hay guys shat is happining here I dont understand
here is the code
i should get 100, 100 but i get this 1, 2242648Code:int main(int x = 100, int y = 100) { cout << x << ", " << y << endl; cin.ignore(); }
so how do I fix this or what did i do rong
This is a discussion on so how do I fix this or what did i do rong within the C++ Programming forums, part of the General Programming Boards category; hay guys shat is happining here I dont understand here is the code Code: int main(int x = 100, int ...
hay guys shat is happining here I dont understand
here is the code
i should get 100, 100 but i get this 1, 2242648Code:int main(int x = 100, int y = 100) { cout << x << ", " << y << endl; cin.ignore(); }
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.
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?
main has some prototypes that are legal, and others aren't. see the faq for more information.
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.
sorry not the right code here
Why is x and y returning that value when nothing else was changed?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)%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(); }
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.
x and y are never initialized, so you're getting junk data.
Do you use compiler warnings?
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.
How to enable warnings or junk data problem? You're being unclear.
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.
Code:int x = 100, y = 100;
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.
Erm, you want the click function to store information in x and y? If so, then read the references tutorial at the site.
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 useThis 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.Code:int click(int &x, int &y)
--
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.