more else if help :)

i am having trouble getting all of my conditions to be well, conditions. it seems it will check if the response == X, then it will sort of ignore the rest of the conditions( the !=NAN) to a degree. if it fails its supposed to skip it and then read out an error later on in my code, what is happening is it still runs the equation and instead spits out "X = (Xo+((V+Vo)*t)/2)" "Distance(X) = 'NAN'"

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
else if ((response == "X"||response =="x"||response =="length"||response =="distance"||response =="Distance") &&Xo!= NAN && Vo!=NAN&&V!=NAN&&t!=NAN)
        {
            X = (Xo+((V+Vo)*t)/2);
            cout.precision(5);
            cout <<"X = (Xo+((V+Vo)*t)/2)"<<endl;
            cout <<" Distance(X) = '"<<X<<"'"<<endl;
            a = (NAN);
            X = (NAN);
            Xo = (NAN);
            V = (NAN);
            Vo = (NAN);
            t = (NAN);
            system("pause");
            system("ClS");
        }
NaN is a strange value. It doesn't compare equal to any value, not even when comparing it to itself. If you want to know if a value is a NaN you should use std::isnan.

http://en.cppreference.com/w/cpp/numeric/math/isnan
Last edited on
@Peter87 is that a non accessible metadata flag?

@kam975 just for curiosity, why "ClS" and not "cls" or CLS"?
barnack wrote:
@Peter87 is that a non accessible metadata flag?

A what?
Last edited on
@peter87 huh makes sense thanks, how would i check if a variable isnt NAN, i get the double negative so maybe to check if a variable IS a number in a if statement. appreciate the help!

@barnack frankly i have no idea i mustve done something weird when i was typing it and never fixed it
how would i check if a variable isnt NAN


 
!isnan(variable)

so i attempted to use !isnan(variable) and it still didnt work to what i used so i tried isnan(variable)==0 and that seemed to work, for anyone that might have the same issue i did
!isnan(variable) and isnan(variable)==0 should give you the same result.
Last edited on
Registered users can post here. Sign in or register to post.