#include <iostream>
#include <cmath>
using namespace std;
int main() {
int n = 5;
float area = 0.0;
float totalarea = 0.0;
float dx = 1.0/n;
float x = 0.0;
cout << "number of rectangles?:";
cin >> n;
for (int i=1; i<=n; i++){
area = (1/n) * pow(1.0 - pow(x,2.0),0.5) ;
totalarea += area;
x = x + dx;
}
cout << totalarea << endl;
return 0;
}
I am trying to estimate the area of a quarter circle using rectangles. When I enter 1, I get 1 as the output. When I enter an integer 2-6 I get 0 as the output. When I enter an integer above 6, I get "not a number" as the output. Can someone help me fix my code.