sum two numbers using ONE variable.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DEP
    New Member
    • Mar 2007
    • 2

    sum two numbers using ONE variable.

    hi everyone,

    can anyone tel me how to make a code in c/c++ which inputs two numbers from the user and add them by using ONE and only ONE variable in the entire program.
  • lqdeffx
    New Member
    • Mar 2007
    • 39

    #2
    you could probably do it with strings or char* otherwise some ambiguous old school C/assembly way i'm sure. Would you consider using registers as a variable?

    Comment

    • sicarie
      Recognized Expert Specialist
      • Nov 2006
      • 4677

      #3
      I would think another option would be to overload the '>>' operator...

      Comment

      • lqdeffx
        New Member
        • Mar 2007
        • 39

        #4
        what my overly-complicated suggestion not good enough?

        Comment

        • sicarie
          Recognized Expert Specialist
          • Nov 2006
          • 4677

          #5
          Originally posted by lqdeffx
          what my overly-complicated suggestion not good enough?
          Haha, of course it was good, I was merely offering another method. Personally I find pointers easier to use than overloading and re-including header files, or however you choose to implement, but the concept might be easier.

          I'm actually just threatened by your posts - wanted to try to solidify my 'Moderator' status by padding the post count (not that I'm doing that here either....ooooh ! almost at 800!)

          Comment

          • DeMan
            Top Contributor
            • Nov 2006
            • 1799

            #6
            Since you know that there are two numbers....(and given you only use 1 var I assume you're not looking for robust code, and don't have to check validity of input etc (in my favourite pseudicide ):

            Code:
            int a=0;
            
            a = a + getch();
            a = a+ getch();
            Now pray that the user only enters numbers less than 255.....Or you can probably find a better function to read inputs......

            Comment

            Working...