473,512 Members | 14,457 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

sum two numbers using ONE variable.

2 New Member
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.
Mar 13 '07 #1
5 6094
lqdeffx
39 New Member
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?
Mar 13 '07 #2
sicarie
4,677 Recognized Expert Moderator Specialist
I would think another option would be to overload the '>>' operator...
Mar 13 '07 #3
lqdeffx
39 New Member
what my overly-complicated suggestion not good enough?
Mar 13 '07 #4
sicarie
4,677 Recognized Expert Moderator Specialist
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!)
Mar 13 '07 #5
DeMan
1,806 Top Contributor
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 ):

Expand|Select|Wrap|Line Numbers
  1.  
  2. int a=0;
  3.  
  4. a = a + getch();
  5. a = a+ getch();
  6.  
Now pray that the user only enters numbers less than 255.....Or you can probably find a better function to read inputs......
Mar 13 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
8671
by: cplusplus | last post by:
Hello, I have newbie question. I'm stuck on this current assignment. Write a program that prompts the user for two integer values, passes the values to a function where they are multiplied...
0
749
by: August1 | last post by:
This is a follow up to using these functions to produce lottery numbers to an outfile, then read the numbers from the file to the screen. Although other methods are certainly available. ...
8
5784
by: simpleman | last post by:
Hi, I have an assignment that requires me to subtract two very large unsigned integers using linked list.AFAIK I have to manipulate data as character. But I dont know how to get input into the...
17
7440
by: Steve Jorgensen | last post by:
If you've ever employed custom error numbers and messages in you programs, you've probably ended up with code similar to what I've ended up with in the past something like... <code> public...
21
16825
by: Abhishek Jha | last post by:
hello all, this has been an interesting topic since long. you can swap two numbers (say a and b) using temp(as third variable). you can also swap without using third variable.likeThis was also...
19
5144
by: youpak2000 | last post by:
Are MAGIC numbers always bad? Using magic numbers (constant numbers) in programs are generally considered a bad programming practice, and it's recommended that to define constants in single,...
4
6305
by: nirjhar.oberoi | last post by:
Hi, This is my first post on this group! i am beginner lever C programmer. I am trying to add two numbers or multiply them using a single variable! Your are not allowed to use Unions or any...
6
2617
by: Nirjhar Oberoi | last post by:
Hi, Can you add two numbers using a Single Variable? :-) If yes then show me the code!!! Regards Nirjhar
11
1908
by: Masud | last post by:
hi, for a test i want to generate different random numbers between different ranges in a single loop. I tried to solve in the following way but it always profile same value. I am looking for...
0
7153
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7373
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7432
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7519
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5677
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5079
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3218
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
796
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.