błąd typu nan

0
#include <iostream>
using namespace std;
 float e=0.000000001;
float f(float x)
{
    return x*x+2*x-15;
}
float m(float a,float b)
{

    float mid=(a+b)/2;
    if(f(mid)<e)
    {
        return mid;
    }
    else
    {
        if(f(a)*f(mid)<=0)
        {
            m(a,mid);
        }
        else
        {
            m(mid,b);
        }
    }
}

int main()
{
    float a,b;
    cout << "Podaj przedzial" << endl;
    cin>>a>>b;

    if(f(a)*f(b)<=0)
    {
      cout<<m(a,b);
    }
    else
    {
        cout<<"brak miejsc zerowych";
    }
    return 0;
}
2

Gdzie twoja funkcja m ma return? Jak wejdziesz w else to na zaden return już nie trafisz :( Zresztą kompilator przecież protestuje:

<source>:27:1: warning: non-void function does not return a value in all control paths [-Wreturn-type]
0

@Shalom: a no tak, myślałem, że nie trzeba return

1

if(f(mid)<e) może jednak if(fabs(f(mid))<e)

0

cout<<"brak miejsc zerowych";

Ale to jest przecież błędny komunikat...

1 użytkowników online, w tym zalogowanych: 0, gości: 1