Trying to get the correct output!!!!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include <iostream>
#include <cmath>

using std::cin;
using std::cout;
using std::endl;

double func_1(double);
double func_2(double);
double func_3(double);
double func_4(double);
double func_5(double);
double rect_integral(double a, double b, int n, int choice);
double trap_integral(double a, double b, int n, int choice);

const char * funcname[6] = {
    "",
    "5x^4 + 3x^3 - 10x + 2",
    "x^2 - 10",
    "40x + 5",
    "x^3",
    "20x^2 + 10x - 2" };

int main () {

    int choice;
    int n;
    double a;
    double b;
    double h;
    double x;
    double area;
    bool trap = false;
    bool rect = false;

    cout << "Functions available: \n\n";
    for (int i=1; i<6; i++)
        cout << "  " << i << "  " << funcname[i] << '\n';
        cout << endl;

        cout << "Choose a function (1, 2, 3, 4, 5, other(quit)) " << endl;
        cin >> choice;

        if (choice >= 1 && choice <= 5)
        {
           char method = ' ';
           do {
               cout << "Would you like to calculate the area using the rectangle,"
                 << " trapezoid, or both (1, 2, 3): " << endl;
               cin >> method;
        } while (method < '1' || method > '3');

        switch (method) {
            
                case '1':
                rect = true;
                cout <<"How many rectangles do you want? " << endl;
                break;
                
                case '2':
                trap = true;
                cout <<"How many trapezoids do you want? " << endl;
                break;
                
                case '3':
                trap = true;
                rect = true;
                cout <<"How many rectangles/trapezoids do you want? " << endl;
        }

        cin >> n;

        cout <<"Please select a starting point, a: " << endl;
        cin >> a;

        cout <<"Please select an ending point, b: " << endl;
        cin >> b;

        if (rect) {
            cout << "The area under " << funcname[choice]
                 << " between " << a << " and " <<  b
                 << " is: " <<  rect_integral(a, b, n, choice) << endl;
        }

        if (trap) {
            cout << "The area under " << funcname[choice]
                 << " between " << a << " and " <<  b
                 << " is: " <<  trap_integral(a, b, n, choice) << endl;
        }
    }

    return 0;
}

double func_1 (double x)
{
    return 5.0*x*x*x*x + 3.0*x*x*x - 10.0*x + 2.0;
}

double func_2 (double x)
{
    return x*x - 10.0;
}

double func_3 (double x)
{
    return 40.0*x + 5;
}

double func_4 (double x)
{
    return x*x*x;
}

double func_5 (double x)
{
    return 20.0*x*x + 10.0*x - 2.0;
}

double rect_integral(double a, double b, int n, int choice)
{
    // here insert the code to calculate the integral
    return 1.0; // dummy value
}

double trap_integral(double a, double b, int n, int choice)
{
    // here insert the code to calculate the integral
    return 2.0; // dummy value
}


this code compiles but I need to get the program to do this:

Choose a function (1, 2, 3, 4, 5, other(quit)): 1
Would you like to calculate the area using the rectangle, trapezoid, or both (1, 2, 3): 2
How many trapezoids do you want? 1000
Please select a starting point, a = 1
Please select an ending point, b = 2
The area under 5x4 + 3x3 – 10x + 2 between 1 and 2 is 29.25

I need the program to output 29.25 but I cant figure out what to. Help please. help with code!
And here is some more information:

n = number of rectangles and/or trapezoids
a = beginning x value
b = ending x value
h = width of each rectangle/trapezoid, (b-a)/n
f(x) = height of rectangle
(f(x1)+f(x2))/2 = height of trapezoid
Area = width*height

Integration Program Definition: Your program should determine the area under these different functions,
f1(x) = 5x4 + 3x3 – 10x + 2
f2(x) = x2 – 10
f3(x) = 40x + 5
f4(x) = x3
f5(x) = 20x2 + 10x – 2
Topic archived. No new replies allowed.