Thread: Help Please!!!!!!!

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    55

    Help Please!!!!!!!

    I am trying to do a college assignment. I need to take 5 numbers and get the sum. This part is no problem.

    I also need to tell the user if the number they just entered is the same as one already stored in one of the variables. I can't figure out how to do this. Can anyone help point me in the right direction?

    I also need to tell the user if they have entered an odd or even number? How the heck do you do this? I have looked and looked in my text book but can't find information on it.

  2. #2
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,823
    For the odd or even thing, look up the modulus operator.

    As for the other problem, just check the value against the variables you need to...
    if(a == b), etc...

  3. #3
    Registered User Cela's Avatar
    Join Date
    Jan 2003
    Posts
    362
    >>I also need to tell the user if the number they just entered is the same as one already stored in one of the variables.
    Use an array of five numbers to hold the input, with each new number, test it against all values already in the array.

    >>I also need to tell the user if they have entered an odd or even number?
    Code:
    if (num % 2)
    { 
      /* Even */
    }
    else
    {
      /* Odd */
    }
    *Cela*

  4. #4
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    what makes a number even?

    num / 2 always produces a remainder of zero.

    the operator that lets you get the remainder from an integer division is the modulus operator %

    % does an integer division and returns the remainder. i.e.

    10%3 is 1.

    You know how enough information to do this without me actually elling you how exactly!
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  5. #5
    Registered User
    Join Date
    Jan 2003
    Posts
    55
    I'm still having a problem. The text book chosen for th course sucks. I think I am going to have to buy a different book.

Popular pages Recent additions subscribe to a feed