always output is -50 whatever i type :(

+4 Mayank Verma · February 25, 2015

i dont know what to do.

Post a Reply


- page 1
Oldest  Newest  Rating
0 c student · February 25, 2015
int main?
0 Jco Bea · February 25, 2015
you sure that you run the test.cpp code?
0 Jason Amador · February 25, 2015
What is in main.cpp?
0 Abdullah Nauman · February 25, 2015
Yes, what is in main.cpp
+1 Jay Deshaun · February 25, 2015
It seems as if you're compiling and executing the "main.cpp" file instead of the "test.cpp" file.

Try saving and closing the "main.cpp" file and then open a new file with the same name but in a different folder and then copy and paste the "test.cpp" contents/code into the new "main.cpp" file.
0 Mayank Verma · February 26, 2015
when i deleted main.cpp then it worked fine
can anybody explain me what just happened, why it didn't work earlier
+1 c student · February 26, 2015
when you compile one or more files, it will compile with main as the "main" code where everything else is attached.  when your program is run, it will look for main and start running from there. here's an example:

in the main file, you have:

int test (void); /* test function prototype */

int main (void) { /* your program starts here */


return 0;


in another file you have:

int test (void) {

/* your code here */

return 0;


when you compile, it will essentially stick these two together into one but it will always start off in main.  it will run main and see your function test which you have defined above and then find that function, which has been elaborated in the other file, and run it.
0 K D · February 26, 2015
You can't run a program if there is no main function you can compile it but you can't run it...  So Code::Blocks was probably running main.cpp.
0 Mayank Verma · February 26, 2015
thanks C Student but can you elaborate what is  /* test function prototype */
these are the files:
+1 Abdullah Nauman · February 26, 2015
Since C++ reads your code from top to bottom, you n to prototype your code. The if you don't prototype it, then when you call that function from main, it will not recognize that function since it has not gotten to it yet. I am not really the best teacher so I will let Bucky tell you how to prototype functions.">
  • 1
  • 2



Used in many types of software including music players, video games, and many large scale applications.

Bucky Roberts Administrator