c /c++ program to find area under a curve by monte carlo method

#include <iostream>
#include <cstdlib> // for: rand(), srand(), and RAND_MAX
#include <ctime> // for: time(), accessing the system clock
#include <cmath> // for: fabs(), sin()
using namespace std;
float const PI = 3.141593;
float find_area(float hi_x);
// evaluate the area under the sine(x) curve,
// x between [0, hi_x], where hi_x is <= PI
int main()
{
float area, rel_error, true_value;
cout << "integral of sine(x) between 0 and PI\n";
area = find_area(PI);
true_value = 2.0; // known result
rel_error = fabs((true_value - area)/true_value);
cout << "The correct analytical result is " << true_value << endl;
cout << "integral is approximately " << area << endl;
cout << "relative error is " << rel_error << endl;
return 0;
}

// find area under sine(x) curve between x = [0, hi_x]
// by the Monte Carlo Method
// constants: PI = 3.141593
// pre: argument hi_x has a positive value
// post: estimated area has been returned
// <your name> <date>
float find_area(float hi_x)
{
// the method goes here;
return 0; // (replace this stub)
}
Cheers!
But there's nothing in your find_area() function.
Topic archived. No new replies allowed.