Sunday, August 2, 2009

I need to create a random function in c++ using this formula =f(x) × 100 , f(x) = (pi + x)^5?

i need the help fast plz

I need to create a random function in c++ using this formula =f(x) × 100 , f(x) = (pi + x)^5?
I can give you video tutorial on how to use the rand() function:





http://xoax.net/comp/cpp/console/Lesson2...





I hope that helps. Could you give some clarification?
Reply:I shall give you some quick and dirty code which implements the formulae you have given me. It is random in the sense that anything I do is random and unfocused when it's quick and dirty. Its output is not random because it always seems to return 1. Obviously, you'll have to debug it yourself (but this sounds like homework so you should anyhow) and this may help anyhow.





#include %26lt;iostream%26gt;


#include %26lt;cmath%26gt;





using namespace std;





float funky(float );





int main()


{





double x, Rand;


int i;





cout %26lt;%26lt; "Enter a number:";


cin %26gt;%26gt; i;





x=(double) i;





Rand=funky(x)*100.0;





cout %26lt;%26lt; rand;


return 0;


}





float funky(float x)


{


double pi=3.14159;


double temp1, temp;


temp=(pi*x);


temp1=pow(temp,5);


return temp1;


}


No comments:

Post a Comment