Adding large numbers - dynamic variables

I'm trying to add numbers that are larger than the max value for an int. So I'm storing the numbers in arrays, however, it isn't even letting me type numbers into my second array from the console. Any suggestions?

Thanks in advance!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <iostream>

using namespace std;



int main(int argc, char** argv) {
	
	int *pVar, *qVar, *tVar;
	int arraySize;
	
	cout << "Enter array size: ";
	cin >> arraySize;
	pVar = new int [arraySize];
	qVar = new int [arraySize];
	
	cout << "Enter an integer: ";
	for (int i = 0; i < arraySize; i++)
	{
		cin >> pVar[i];
	}
	
	cout << "Enter another integer: ";
	for (int j = 0; j < arraySize; j++)
	{
		cin >> qVar[j];
	}
	
	tVar = new int [arraySize + 1];
	
	for (int k = 0; k < arraySize + 1; k++)
	{
		tVar[k] = pVar[k] + qVar[k];
	}
	
	for (int m = 0; m < arraySize + 1; m++)
	{
		cout << tVar[m];
	}
	
	
	return 0;
}
Can someone please help me with this?
Why not use QWORDs?

typedef unsigned __int64 QWORD;//assuming they're unsigned

Note that __int64 is not a set standard type, there's no guarantee it's 64 bits.
Your compiler may not support it.
Last edited on
I don't know what QWORDs is? I'm just supposed to use pointers and dynamic variables
Oh, I hadn't realized this was an assignment. Ignore what I said, sorry for the confusion.

I'll take a more thorough look at your code, and I'll edit this post once I'm back.

*EDIT* the code works fine for me. I think the problem may be that you are entering the whole number with several digits, when you should actually be entering the individual digits, one at a time - because that's how your loop is set up.

Note that each element of your dynamic arrays are integers. Assuming they are 32-bit signed integers, each element can hold a value of -2147483648 through 2147483647.

What I'm getting at is that I think you think you're doing this:

Input: 1024

[1][0][2][4]



When you're actually doing this:


Input: 1024

[1024][][][]
Last edited on
Topic archived. No new replies allowed.