Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7590189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:20:32+00:00 2026-05-30T20:20:32+00:00

I am trying to create a program in C++ that will use the bisection

  • 0

I am trying to create a program in C++ that will use the bisection method on a cubic function to find a root of that cubic function. Now I have this:

#include <iostream>
#include <cmath>

using namespace std;

int functie(double a,double b,double c,double d,double x){
    double y;
    y = (a*x*x*x + b*x*x + c*x + d);
    return y;
}

int main(){

    int a,b,c,d;//no comment

    cout << "enter of form: ax^3 + bx^2 + cx + d (integers)" << endl << "a: ";
    cin >> a;
    cout << endl << "b: ";
    cin >> b;
    cout << endl << "c: ";
    cin >> c;
    cout << endl << "d: ";
    cin >> d;

    double min, max, temp;

    min = -100;
    max = 108.54267542;
    while(functie(a,b,c,d,max) == 0 ||functie(a,b,c,d,min) == 0 ){
    temp = (max + min)/2;
    if(functie(a,b,c,d,min) < 0 && functie(a,b,c,d,temp) < 0 || functie(a,b,c,d,min) > 0 && functie(a,b,c,d,temp) > 0){
           min = temp;
    } else {max = temp;}
    }
    cout << min << endl;
    cout << max << endl;
    cout << temp << endl;
    system("pause");
    return 0;
}

but it doesn’t work; the cout’s at the end of the program only output the input values.
(and in case you were wondering why my max value is so weird, is to prevent that when max is +100 and the root is at 0, then the program will crash…)

So if you have got some time and want to check this, thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T20:20:33+00:00Added an answer on May 30, 2026 at 8:20 pm

    Of course it’s wrong. On this line:

    while(functie(a,b,c,d,max) == 0 ||functie(a,b,c,d,min) == 0 )
    

    The loop will execute only when the value returned from functie is zero. The values of max and min should never change.

    And you have declared functie like this:

    int functie(double a,double b,double c,double d,double x)
    

    You’re returning (and you should) a double value from functie, but because of the definition it’s cast into an int.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to create a Ruby program that will be running online
For my program I am trying to create a function that will generate an
I am trying to create a program that will do some simple calculations, but
I am trying to create a program that will set up a crontab to
I am trying to create a program that will tell if a number given
I'm trying to create a program that will display bar graphs with * the
i'm trying to create a program that generates images for use as multi-screen backgrounds,
I'm trying to create a program that takes a text file of c++ code
I'm currently trying to create a program that estimates location based on signal strength.
Alright so what I am trying to do is essentially create a program that,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.