Thread: If, then with + and -, question

  1. #1
    Registered User
    Join Date
    Jan 2004
    Posts
    8

    If, then with + and -, question

    ok I'm vedry new to C. I know if you want to use an interger vairiable you put scanf("%d", X) then you put if X = 2 then do this.

    how do you put if X = + or X = -?

    what are the mathmatical sybols? do they fall in the character category or what?

  2. #2
    Registered User
    Join Date
    Jul 2003
    Posts
    85
    First, it should be:

    scanf("%d", &X);

    Then to test if it's positive or negative, just use the less/greater than symbols.

    Code:
    if( X < 0 ) {
         /* X is negative */
    }
    if( X > 0 ) {
         /* X is positive */
    }
    if( X == 0 ) {
         /* X is zero */
    }
    You could also use if else statements if you preferred.

Popular pages Recent additions subscribe to a feed