I have a problem That im stuck on and looking for some help.

The problem is:

you need to write a program to calculate the area under a curve f(x) = 10x3 + 24x2 – 3x + 8 for a <= x <= b where a and b are greater than or equal to 0. First, you use cin to input the starting point and ending point, a and b, of the range of x values you are interested in. Use if statements to check whether a and b are larger than 0, and whether a is smaller than or equal to b. If NOT, error message must be displayed and the program terminates. If YES, your program approximates the area under the curve between a and b by partitioning the area into small segments where each segment has width (called w, and it is another input by cin) equal to 0.01 (for example). For example, when a=2 and b=6, your program finds the area of the first segment by multiplying 0.01 and f(2.01). The second segment area can be calculated by 0.01 x f(2.02). The values of segment areas are summed together. The process is repeated using a while loop until f(6) is calculated.

My problem is at the end with the while loop to calculate the area for the segments of the curve, getting the codes correct for the curve itself and to get the x to multiply by the segment length and then add to itself each time.

This is my code so far:

#include <iostream>

#include <cmath>

using namespace std;

int main()

{

int a;

int b;

double w;

double x;

double y;

//Ask user for the value of A, and check to make

//sure it is greater than or equal to zero.

cout << "Please enter a value for A, the starting point: ";

cin >> a;

if (a < 0)

{

cout << "A must be greater than or equal to zero!" << endl;

return 0;

}

//Ask user for the value of B, and check to make

//sure it is greater than or equal to zero.

cout << "Please enter a value for B, the ending point: ";

cin >> b;

if (b < 0)

{

cout << "B must be greater than or equal to zero!" << endl;

return 0;

}

//Check to make sure that A is less than or equal to B.

if (a > b)

{

cout << "A must be less than or equal to B!" << endl;

return 0;

}

//Have the width input by the user.

cout << "Please enter a width of segments: ";

cin >> w;

//Calculations for the curve

while (x <= b)

{

x = x+(w + a);

y = ((10 * pow(x, 3.0)) + (24 * pow(x, 2.0)) - (3 * x) + 8);

}

cout << "The area of sector one is: " << y << endl;

return 0;

}

The problem is:

you need to write a program to calculate the area under a curve f(x) = 10x3 + 24x2 – 3x + 8 for a <= x <= b where a and b are greater than or equal to 0. First, you use cin to input the starting point and ending point, a and b, of the range of x values you are interested in. Use if statements to check whether a and b are larger than 0, and whether a is smaller than or equal to b. If NOT, error message must be displayed and the program terminates. If YES, your program approximates the area under the curve between a and b by partitioning the area into small segments where each segment has width (called w, and it is another input by cin) equal to 0.01 (for example). For example, when a=2 and b=6, your program finds the area of the first segment by multiplying 0.01 and f(2.01). The second segment area can be calculated by 0.01 x f(2.02). The values of segment areas are summed together. The process is repeated using a while loop until f(6) is calculated.

My problem is at the end with the while loop to calculate the area for the segments of the curve, getting the codes correct for the curve itself and to get the x to multiply by the segment length and then add to itself each time.

This is my code so far:

#include <iostream>

#include <cmath>

using namespace std;

int main()

{

int a;

int b;

double w;

double x;

double y;

//Ask user for the value of A, and check to make

//sure it is greater than or equal to zero.

cout << "Please enter a value for A, the starting point: ";

cin >> a;

if (a < 0)

{

cout << "A must be greater than or equal to zero!" << endl;

return 0;

}

//Ask user for the value of B, and check to make

//sure it is greater than or equal to zero.

cout << "Please enter a value for B, the ending point: ";

cin >> b;

if (b < 0)

{

cout << "B must be greater than or equal to zero!" << endl;

return 0;

}

//Check to make sure that A is less than or equal to B.

if (a > b)

{

cout << "A must be less than or equal to B!" << endl;

return 0;

}

//Have the width input by the user.

cout << "Please enter a width of segments: ";

cin >> w;

//Calculations for the curve

while (x <= b)

{

x = x+(w + a);

y = ((10 * pow(x, 3.0)) + (24 * pow(x, 2.0)) - (3 * x) + 8);

}

cout << "The area of sector one is: " << y << endl;

return 0;

}

`y = ((10 * pow(x, 3.0)) + (24 * pow(x, 2.0)) - (3 * x) + 8);`

change to

`y `**+=** ((10 * pow(x, 3.0)) + (24 * pow(x, 2.0)) - (3 * x) + 8);

and

`double` y;

to` ``double` y **= 0**;

Last edited on

Topic archived. No new replies allowed.