I have no idea how to do from 4 to 8

1. Prompt the user Enter a positive number or 0 to quit:
2. Extract the number into int n
3. If the users enters 0, the program should finish.
4. Otherwise, proceed by resizing a vector<double> x so that it has n entries.
5. Set dx = 1.0 / n
3
6. Set x[i] = i*dx for the entire vector
7. Compute the sum s = f(x[0]) + f(x[1]) + ...f(x[n−1]) where f(x) =
√1−x2.
8. Multiply the sum by its value and 4*dx.
9. Print the value of the sum on one line.
10. Print the value of PI on the line below.
What have you coded ?
#include "std_lib_facilities.h"
int main ()
{
int n;
while (true)
{
cout << "Enter a positive number or '0' to quit.\n";
cin >> n;
if (n == 0)
{
cout << "The program has finished.\n";
break;
}
else
{
vector<double> x;
x.size() = n;
dx = 1.0 / n;
x[i] = i * dx
y = sqrt(1 - x^2);
s =

cout << "The value of the sum is: " << s << ".\n"
<< "The value of log(2) is: " << log(2) << ".\n";

}
}



Thats as far as I got.
Topic archived. No new replies allowed.