I'm trying to write a program for class and I can't get my fractional exponent to work. I've tried using 2/3 2.0/3.0 and I've tried entering 2/3 into a separate variable, but nothing seems to work. I don't get any errors while building 2/3 but the logic does not come out correctly. I keep getting "undefined reference to 'pow' as an error which doesn't seem right at all because I'm entering two parameters as required. Here is my code:

//find hydraulicRadius to the power of 2/3
	double twobythree = 2.0/3.0;
	printf("%lf = 2/3\n", twobythree);

	double r = pow (hydraulicRadius, twobythree);

Recommended Answers

All 6 Replies

post the whole program. In the code you posted the variable hydraulicRadius was not defined. Did you include <math.h> ?

post the whole program. In the code you posted the variable hydraulicRadius was not defined. Did you include <math.h> ?

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

//////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////

//function prototypes
//char* allLower(char*);
//int toppingCost(int, int);
//char* customers(int);
double findFlow(double);

//////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////

//change string to all lowercase
/*char* allLower(char *name){
 int i = 0;
 while(name[i] != '\0')
 {
	 name[i] = tolower(name[i]);
	 ++i;
 }
 //return string in lowercase
 return name;
 }*/

//////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////


static double initialDepth=5.0;
static double channelWidth=15.0;
static double channelDepth=10.0;
static double roughness=0.014;
static double slope=0.0015;


double findFlow(double depth){
	double flow = 0.0;
	double hydraulicRadius = ( (channelDepth * channelWidth) / ( (2.0 * channelDepth) + channelWidth) );

	printf("%lf = radius\n", hydraulicRadius);

	double square = sqrt(1024);
	printf("%lf = sqrt\n", square);

	//find hydraulicRadius to the power of 2/3
	double twobythree = 2.0/3.0;
	printf("%lf = 2/3\n", twobythree);

	double r = pow (hydraulicRadius, twobythree);

	printf("%lf = radius\n", r);

	flow = ((1.486 / roughness) * (channelWidth * depth) * (r) * (slope / 2) );

	printf("%lf is the flow\n", flow);

	return flow;
}


//double calc


int main() {

	//double depth = 5.0;

	double flow = findFlow(initialDepth);

	printf("%lf is the flow", flow);





	return (EXIT_SUCCESS);
}

Are you compiling on *nix? If so you may need the -lm switch to get math.h properly.

Are you compiling on *nix? If so you may need the -lm switch to get math.h properly.

I'm using Eclipse. I completely forgot about that though, is there a way to build it differently in Eclipse?

Edit: nevermind, searched google and figured it out. Thanks.

to get math.h properly

I meant the math library not math.h itself. That may not be an issue any longer anyway, I'm not up on *nix at all anymore I just remember having to do that from a while ago.

Well, anyway glad it worked out for you.

Just a minor thing, but you could save time declaring like variables:

static double one   = 234.34,
              two   = 34520.0303,
              three = 333.33,
              ...;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.