c++ - How do I call a function from another .cpp file into the file where my int main() is? -
this question has answer here:
so program requires me make function in 1 file, , call another.
i have 1 file called convertdays.cpp this:
#include <iostream> int convertdays(int, int, int); int convertdays(int month, int day, int year) { int date; date = year * 1000 + month * 100 + day; return date; }
then have file int main() stuff is, this:
#include <iostream> using namespace std; int main() { int day, month, year; cout << "please enter month: " << endl; cin >> month; cout << "please enter day: " << endl; cin >> day; cout << "please enter year: " << endl; cin >> year; convertdays(month, day, year); //convertdays stays in red though. //still need add couple of more things not necessary right now. system("pause"); return 0; }
how make work can keep of functions in file , call them in when need them?
make file called "convertdays.h", containing function declaration:
int convertdays(int, int, int);
this called header file.
then @ top of main.cpp
:
#include "convertdays.h"
(it's idea put same thing @ top of convertdays.cpp
, though not strictly necessary.)
then when build executable, link main.o
, convertdays.o
.
Comments
Post a Comment