C++ Programming

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • CLIFFHANGER
    New Member
    • Dec 2007
    • 1

    C++ Programming

    Hello everybody.
    I want to write a program that the user enters 3 numbers and the output must distinguish which number is even and which is odd, using 2 void functions which will display those numbers and their kind (even or odd).
    Can someone help me, because i out of ideas?

    Thanks.
  • abhisoni
    New Member
    • Dec 2007
    • 12

    #2
    Hi,

    This is a very simple program and needs just 3-4 minutes. U said u ran out of ideas. Can i know what was u'r initially thought direction ? Try more folk it's really too simple.

    Hint :: Just use the MOD operator or the BINARY OR.

    Comment

    • Idriss
      New Member
      • Dec 2007
      • 1

      #3
      Originally posted by abhisoni
      Hi,

      This is a very simple program and needs just 3-4 minutes. U said u ran out of ideas. Can i know what was u'r initially thought direction ? Try more folk it's really too simple.

      Hint :: Just use the MOD operator or the BINARY OR.

      Hello there,

      Well I'm not sure why you need two void functions to simply tell an odd number from even one, any way you might want to try this algorithm :

      for i<3
      function InputNumber(x)
      y=x%2
      i=i-1;
      if y==1 then
      return true;
      else
      return false ;

      Hope that will help

      Comment

      • sicarie
        Recognized Expert Specialist
        • Nov 2006
        • 4677

        #4
        So you need to design three different functions - your main(), your function to figure out if something is even, and your function to figure out if something is odd.

        Assuming you know how to construct a main that asks for three variables, I would then start prototyping your even and odd functions. You are going to have to make a design decision here - are you going to pass all three variables to a function, and let it handle IO, or are you going to have your main() handle the IO based on the return of a single number?

        Then that will lead you into your prototype, and two of the three things needed to prototype a function.

        Once you have the prototype, you can then think about the implementation of the functions.

        Comment

        • weaknessforcats
          Recognized Expert Expert
          • Mar 2007
          • 9214

          #5
          What sicarie is using is the "divide-and-conquer". That is, when you can't of how to do something,you call a function that does it (even if no such function exists). Then inside that function there is yet a thing that you don't know how to solve, then call another function. Eventually, you will have called enougth functions that the code needed will be trivial.

          Sometimes, this is called "top-down" programming.

          Comment

          Working...