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
elseif ((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.
@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
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