473,672 Members | 2,615 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 6102
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
8687
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 together and the square root of the product is returned and displayed for the user. The function should return a double. Hint: If you multiply an integer by 1.0 the result will be a double. For example:
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. #include <iostream> #include <fstream>//for declaring objects of the ofstream and ifstream #include <time.h> #include <stdlib.h> using namespace std;
8
5795
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 linked list since the input will all be in one line. eg. 1234567890. Also I have to use one integer per node. Any help/suggestion will be greatly appreciated. Thanks in advance
17
7453
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 Const xyzcErrNumBase As Long = 500 Public Const xyzcErrNumHeyDontDoThat = xyzcErrNumBase + 1 Public Const xyzcErrTxtHeyDontDoThat = "Hey! Don't do that!"
21
16850
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 done in three statements. Can anyon suggest this swapping in anything less then that.
19
5161
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, visible place in a header file. My question is that is there any situation where using magic numbers is not necessarily a bad thing? lets say that we want to initialize some private variables in a class using some constant default numbers, can we...
4
6316
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 other userdefined DS! Inline assembly is accepted! but use only "One Variable" Thanks
6
2626
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
1924
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 suggestion in this regard. #include <cstdlib> #include <time.h> #include<iostream.h>
0
8486
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8828
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8608
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7446
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5705
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4227
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2819
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2063
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1816
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.