Question about NaN in C++

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jjblackfox
    New Member
    • Feb 2008
    • 2

    Question about NaN in C++

    Hello everyone.
    I am new to C++ and I am currently working through a book that is helping me out a lot.
    I created an infinite for loop that will take numbers that users input and add them together. I have an int variable inside my for loop that adds to the total int outside the for loop.

    I want the for loop to break if what they type is not a number. Currently, if you type in a NaN, it continously outputs text.

    Something like:
    if(NaN(total))
    {
    break;
    }

    Any help would be greatly appreciated.
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    What do you mean by "not-a-number" ??

    Considering everything in the computer is a number, adn considering that if you use an int for data entry, you have to enter an int.

    Exactly, what are you trying to do??

    Comment

    • jjblackfox
      New Member
      • Feb 2008
      • 2

      #3
      Originally posted by weaknessforcats
      What do you mean by "not-a-number" ??

      Considering everything in the computer is a number, adn considering that if you use an int for data entry, you have to enter an int.

      Exactly, what are you trying to do??
      Sorry for not clarifying, I want it to break the for loop when the user types in anything that isn't a number, like a character or string.

      Comment

      Working...