hello guys! sorry if my question might seem dumb. I have anxiety and its hard for me to ask for help but i am a newbie learning c++ as my first language.
today i looked up that you can actually split your code into multiple files to make it organised so i tried to make a very basic program but the main function still doesnt recgonize my function that I put in another file
I believe I did all the includes and if someone can give me some light I really appreciate it >.<!
my main.cpp is:
Code:
#include <iostream>
#include <stdlib.h>
#include "operator.hpp"
using namespace std;
int maint()
{
double c , d;
char operatior;
cout<<"enter first number" << endl;
cin>>c;
cout<<"enter second number" << endl;
cin>>d;
cout<<"choose your operator"<< endl;
cin>> operatior;
affiche_resultat (operatior,c,d); //simulates how a calculator works
return 0;
}
operator.hpp code:
Code:
#ifndef OPERATOR_HPP_INCLUDED
#define OPERATOR_HPP_INCLUDED
void affiche_resultat(char op, double a, double b);
#endif // OPERATOR_HPP_INCLUDED
operator.cpp code
Code:
#include <iostream>
#include <stdlib.h>
#include "operator.hpp"
using namespace std;
void affiche_resultat(char op, double a, double b)
{
switch(op)
{
case '+' :
cout<<"the result is"<< a+b << endl;
break;
case '-' :
cout<<"the result is"<< a-b << endl;
break;
case '*' :
cout<<"the result is"<< a*b << endl;
break;
case '/' :
if (b=0)
{
cout<<"Never devision by 0"<< endl;
}
else
{
cout<<"the result is" << a/b <<endl;
}
break;
default:
cout<<"error operator not valid"<< endl;
}
}
Edit Sorry forgot to mention the error i keep getting is basically telling me that it cant recognize the function I am using : undefined reference