always output is -50 whatever i type :(

+4 Mayank Verma · February 25, 2015
/images/forum/upload/2015-02-25/f81ad54d87c765327d9f7b1709d4a191.PNG


i dont know what to do.

Post a Reply

Replies

- page 1
Oldest  Newest  Rating
+1 Jason Amador · February 27, 2015
It is only outputting -50 because that is exactly all that your main function does.  You never call test() in main(), you only declare it.  You are clearly a beginner, I would definitely suggest that you stick to single file programs for now and get the feel of the language before getting into using multiple files.  
+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.
+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:
#include 

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

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

test();

return 0;

}

in another file you have:
#include 

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.
+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.  

https://www.thenewboston.com/videos.php?cat=16&video=17485">https://www.thenewboston.com/videos.php?cat=16&video=17485
0 Mayank Verma · February 27, 2015
thanks Abdullah
0 Mayank Verma · February 28, 2015
yeah :P
0 Jco Bea · February 25, 2015
you sure that you run the test.cpp code?
0 c student · February 25, 2015
int main?
0 Jason Amador · February 25, 2015
What is in main.cpp?
0 Abdullah Nauman · February 25, 2015
Yes, what is in main.cpp
  • 1
  • 2

C++

106,983 followers
About

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

Links
Moderators
Bucky Roberts Administrator