jeudi 27 octobre 2016

Mixing in Calculus with nested loops

Good evening everyone!

I have a program I need to write that calculates the area under a curve using the Reimann sum. The endpoints and function will come from user input, which is easy enough. The piece I am stuck on is the nested for loop that will keep track of the intervals. In the assignment it says: You will run the program for 3 different functions, the functions to be supplied to the program as input. The area is to be found over an interval a <= x <= b , so the values for a and b are input. For each function, you will use 3 different subinterval sizes to find 3 different estimates of area. The 3 different subinterval sizes use n = 10, 100, 1000. This is coded in the program, they are not input values.

I am having the hardest time translating what this truly means in retrospect. I am very good at figuring things out once I know the "why". I am supposed to code these intervals into the program using a nested for loop.

for (n = 1; n <= 10; n * 10)
{
    cout << deltax;
    for (n = 10; n <= 100; n * 10)
    {
        cout << deltax;
        for (n = 100; n <= 1000; n * 10)
        {
            cout << deltax;
            }
        }
    }
}

Above is what I have, which just creates an infinite loop. At my current level of knowledge, I am not even sure if I am close to what it needs to look like. I need the program to print the calculated area for each of the subinterval sizes. Any help? I can be more specific if need be, it is even a hard question to ask!

Aucun commentaire:

Enregistrer un commentaire