I was writing a very basic C++ project in CodeBlocks
. I have the following files in the source directory:
add.cpp
#include <iostream>
using namespace std;
void add(void);
void add(void)
{
int num1, num2, sum;
cout << "Enter 2 numbers : " << endl;
cin >> num1 >> num2;
sum = num1 + num2;
cout << "\n";
cout << "Sum = " << sum << endl;
}
sayhello.cpp
#include <iostream>
void sayhello(void);
void sayhello(void)
{
std::string str;
std::cout << "Tell me your name : ";
std::cin >> str;
std::cout << std::endl << "Hello Mr./Ms. " << str << "! Welcome to C++!";
}
main.cpp
#include <iostream>
using namespace std;
int main(void)
{
sayhello();
add();
return 0;
}
But executing the main()
throws the error error 'sayhello' was not declared in this scope
. What am I doing wrong here? I am new to C++ and this is my first project.