Question
C++ area under a curve for equation F(X) = 5x^3 + 7x^2 -3x+4; from 2 to 7 until the difference between the last two calculations
C++ area under a curve
for equation
F(X) = 5x^3 + 7x^2 -3x+4;
from 2 to 7
until the difference between the last two calculations is less than .0001
Why doesnt this code work?
// Source File: test.cpp // Description: calculating the area under the curve
#include
using namespace std;
int main(){ double A = 0; double B = 0; double Area = 0; double height =0; double width = 0; double current_total = 0; double previous_total =0;
A = 2; B = 7; double n =10; double xpos = 0; double diff=1; double prev_width = 0; double prev_n =0; do{ //current total
width = (B - A)/n;
for(double i =0; i Area = height * width; current_total = Area + current_total; } //previous total prev_width = (B - A)/(n-1); prev_n = n-1; for(double i =0; i Area = height * prev_width; previous_total = Area + previous_total; } diff = current_total - previous_total ; n++; }while ( diff > 0.0001); cout << "Result: " << current_total << endl; return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started