Simple logic question

I am a newbie and having some trouble with my logic. Can someone take a look?

I am to write three values as arguments. Return the first argument if it is between the second and third or a -1.0 if the number is not within the range of the second and third numbers.

Also what should i put on lines 55 and 60 after my returns? This is what I have:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
 48 float check_valid_input(float check, float low, float high)
 49 {
 50    float neg = -1.0;
 51    
 52    if(check >= low && check <= high)
 53    {
 54       cout << "middle" << endl;
 55       return check;//unsure where to return too
 56    }  
 57    else (check < low || check > high);
 58    {
 59       cout << neg << endl;
 60       return neg;//unsure where i should return to
 61    }  
 62 }  
> unsure where i should return to

The function returns to the point immediately after its call

> Also what should i put on lines 55 and 60 after my returns?

Nothing. return returns from the function; anything after that is not executed.

else (check < low || check > high); // *** the ; should not be there


1
2
3
4
5
6
7
8
9
10
float check_valid_input( float check, float low, float high )
{
    const float neg = -1.0 ;

    if( check >= low && check <= high ) // if it is in range
        return check ;

    else // otherwise (not in range)
        return neg ;
}

Topic archived. No new replies allowed.