does not equal

This is a discussion on does not equal within the C++ Programming forums, part of the General Programming Boards category; i want to doa thing like if (input != anumber) but what woudl i put meaning not a number 1-9999999999999999999999999999999999999999999999 ...

  1. #1
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608

    does not equal

    i want to doa thing like if (input != anumber)

    but what woudl i put meaning not a number 1-9999999999999999999999999999999999999999999999 (any number)
    Email: Klinerr1@nc.rr.com || AIM: MisterSako || MSN: sakotheinsane@hotmail.com

    -the shroom has spoken

  2. #2
    Registered User fletch's Avatar
    Join Date
    Jul 2002
    Posts
    176
    if ((input >= min) && (input <= max))

    Is this what you're asking?
    "Logic is the art of going wrong with confidence."
    Morris Kline

  3. #3
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    that will work but not exactly
    Email: Klinerr1@nc.rr.com || AIM: MisterSako || MSN: sakotheinsane@hotmail.com

    -the shroom has spoken

  4. #4
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    well i need it to say if it doesnt equal a number
    Email: Klinerr1@nc.rr.com || AIM: MisterSako || MSN: sakotheinsane@hotmail.com

    -the shroom has spoken

  5. #5
    Registered User fletch's Avatar
    Join Date
    Jul 2002
    Posts
    176
    well i need it to say if it doesnt equal a number
    if (input != anumber)
    I'm not picking up what you're putting down. What exactly are you asking?
    "Logic is the art of going wrong with confidence."
    Morris Kline

  6. #6
    Registered User
    Join Date
    Jan 2002
    Posts
    387
    i think he means if they enter a character instead of a number
    "There are three kinds of people in the world...
    Those that can count and those that can't."

  7. #7
    Registered User fletch's Avatar
    Join Date
    Jul 2002
    Posts
    176
    i think he means if they enter a character instead of a number
    Are you asking... If I ask for a numerical input, how do I verify it's a number and not a letter?
    "Logic is the art of going wrong with confidence."
    Morris Kline

  8. #8
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    I think he's asking how to represent java's NaN (not a number). Kinda like 7/0 or something like that.

  9. #9
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    i want it to see if it does not equal a number meaning not a number is a-z !@@##%%^%%^*(#$@# that kind of stuff. a numbe being like math. you know
    Email: Klinerr1@nc.rr.com || AIM: MisterSako || MSN: sakotheinsane@hotmail.com

    -the shroom has spoken

  10. #10
    Registered User fletch's Avatar
    Join Date
    Jul 2002
    Posts
    176
    You're asking...If I ask for input, how do I verify it's a letter and not a number?

    if ( (((int)intput) < 176) && (((int)input) > 185) )

    where input is a char. That's a lot of parenthesis.

    There might be a better way though.
    "Logic is the art of going wrong with confidence."
    Morris Kline

  11. #11
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    that didnt work it if u accidnelty input a character it goes all crazy
    Email: Klinerr1@nc.rr.com || AIM: MisterSako || MSN: sakotheinsane@hotmail.com

    -the shroom has spoken

  12. #12
    gapostolis
    Guest
    Is this you're looking for?

    ----------
    code :
    ----------

    #include <iostream.h>

    typedef unsigned long int lint;

    int main()
    {
    lint input;
    lint num = 100;
    lint max = 4294967295;

    cout<<"Give a number : "<<endl;
    cin>>input;

    if ( ((input >= 1) && (input <= max)) && (input != num) )
    cout<<"Ok";
    else
    cout<<"Not Ok";

    return 0;
    }

  13. #13
    Registered User moonwalker's Avatar
    Join Date
    Jul 2002
    Posts
    282

    hmm

    i dont know if there's a better way of doing this, but..

    here's how i would do it :-

    get the input to an array...

    check out through each element of the array and see
    if there's atleast 'one' element that is other than
    0,1,2,3,4,5,6,7,8,9 (and) '.' (if you're also considering
    floating points) .. and '-' ... and so on... (note that
    - and . can't repeat in the array)

    (i've done this before... let me check if i still have it )
    meanwhile, try it with these clues..

  14. #14
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    if you stillahve puuullllleaaaaaase send it!
    Email: Klinerr1@nc.rr.com || AIM: MisterSako || MSN: sakotheinsane@hotmail.com

    -the shroom has spoken

  15. #15
    Registered User
    Join Date
    Jan 2002
    Posts
    387
    Searching around on MSDN i found this function:

    Code:
    #include <ctype.h>
    
    //..
    
    if( isdigit(input) != 0 )
    {
    	// input is a digit
    } else {
    	// input is a character
    }
    "There are three kinds of people in the world...
    Those that can count and those that can't."

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Equal compare
    By George2 in forum C Programming
    Replies: 1
    Last Post: 11-10-2007, 05:26 AM
  2. compare if 2 string types are equal
    By sujeet1 in forum C++ Programming
    Replies: 4
    Last Post: 06-06-2007, 07:37 PM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 04:00 PM
  4. set string array equal variable
    By WaterNut in forum C++ Programming
    Replies: 3
    Last Post: 06-29-2004, 06:02 PM
  5. how can 0.00665 not equal 0.00665??!!
    By Susan in forum C++ Programming
    Replies: 10
    Last Post: 02-10-2002, 02:33 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21