Hello all,
I'm trying to link two files but I get error "multiple definition of `funny_words()' " I don't know what to do, as I'm new to C++. I'm reading PROGRAMMING IN C++ by P.B. Mahapatra and the topic is PREPROCESSOR. I have to learn how to Link headers, and cpp files using # include. My first trial with cpp have failed.
Soo much words, but here are two source codes:
1. main.cpp
#include <iostream>
#include "hello.cpp"
using namespace std;
//declare the class
class triangle{
//only visiblein class, invisible outside
private:
int base;
int height;
int area;
//visible both in and outta class
public:
int triangle_area();
int get_values();
};
int triangle::triangle_area()
{
area = 0.5*base*height;
return(area);
}
int triangle::get_values()
{
//prompt for triangle base
cout<<"Please Enter the value of the triangle base"<<endl;
cin>>base;
//prompt for triangle height
cout<<"Please Enter the value of the triangle height"<<endl;
cin>>height;
}
int main()
{
class triangle ABC;
ABC.get_values();
int area;
area = ABC.triangle_area();
cout<<"The area of Triangle is "<<area <<endl;
funny_words();
return 0;
}
2. hello.cpp
#include <iostream>
#include <cmath>
#define GEQUAL >=
using namespace std;
//function to display some funny words
int funny_words()
{
int iq_test;
cout<<"What is your IQ ?"<<endl;
cin>>iq_test;
if (iq_test GEQUAL 50)
cout<<"You got it! Excellent!"<<endl;
else
cout<<"Sorry! you need to pray more for wisdom!"<<endl;
}
Thanks all!