Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using a function in a calculation

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi, I have a quick question. I am trying to use a function in a calculation. I have a function called "Calc_Formula()" and it returns the sum of two numbers. In a seperate .cc file I try to call the function as followed.

#include "formula.h" // formula.cc is location of my Calc_Formula() function formula.h holds the class for formula

int Tots()
{
double first = 0.0;
double second = 0.0; // two seperate variables to
break up calculation

// Problem occuring below with the formula::Calc_Formula()
first = (25 + formula::Calc_Formula());
second = (25 - formula::Calc_Formula());

return (first / second);
}

can someone show me why this is incorrect? I get an error for some reason. I am just not sure how to use a function that returns a value. Thanks
 
I dont think the funciton is bad... make sure you are building your cpp or cc file and it is part of the project.

Also, post the error... that may help too.

Matt
 
How do I make the .cc file part of my project. I included the formula.h in the example shown file. Do I need to defien the formula.cc if so, how? Thanks
 
You would go to the insert menu and insert the cc file into the program

Matt
 
if you use "formula::Calc_Formula()", in class formula you have to declare Calc_Formula() as static function.
Or you can create an instance MyFormula of class formula in the class which hold the function Tots() or within Tots() itself and then call MyFormula.Calc_Formula().
 
In my class Calc_Formula is a static function (which is in my .h file) Then I use Calc_Formula in a seperate .cc file called Form2.cc which #include "Formula.h" Then I need to somehow be able to call the Calc_Formula within the Formula.cc and that is where I am having the problem. So can anyone show me what I should do? Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top