help me with this program :

#include <iostream>
using namespace std;

#include <math.h>

double F(double x){
        double res = pow(x, 9) - pow(x, 7) + 2 * pow(x, 2) -1;

        return res;

void print_roots(){
        double low = 0, high = 1;

        for(int i = 0; i < 1000 ; ++i){
                double mid = (float)(low + high)/2;
                double val = F(mid);

                cout << mid << ":" << val << endl;

                if(val < 0.00001 && val > -0.00001){
                        cout << "Root is " << mid << endl;
                else if (val < 0 )
                        low = mid;
                        high = mid;

int main(int argc, char **argv){
        return 0;

can it be made to add induction of different interval or different task.
i mean to assign a task and interval and the program to give resolution.
example : i start the program and it ask me to enter the task(bisection method) after entering it to ask me the intervals and when we do this to show the answer.
thank you in advance.i hope you understand me.sorry for bad english

Yes, you should be able to do that. You might want to look up use of switch statements and use a menu to select the task. Here's a rough sketch of the process, but looking it up in a book to learn the details is strongly recommended.

cout  << enter the number before the task you want to do
cout << 1) bisection
cout << 2) foo
cout << 3) bar

cin >> selection
   case 1:
      cout << "enter the interval you wish to use
      cin >> interval
   case 2:
   case 3:

There are alternative ways to accomplish the same thing, but this is usually one of the easier methods to understand.

This article has been dead for over six months. Start a new discussion instead.