Large Integer Arithmetic Assignemt: Lost, HELP!!

This program is supposed to read in an integer that defines how many digits two more numbers can be, and then adds those numbers. The code is as follows, but I can't figure out for the life of me how to fix this. It seems that it is having issues storing the ASII values at line 63.

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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <iostream>
#include <iomanip>
using namespace std;


 
void print_number(int num[], int sz, int sz_used);
void new_line(); 
void get_number (int num[], int sz, int & sz_used);

int main ()
{
    int size;
    int digit_length;
    int *number_1;
    int *new_int[0];
    
    cout << "phase 1..... " << endl;
    cout << "Enter the size: " << endl;
    cin >> size;
    
    number_1 = new_int[size];
    new_line();
    get_number(number_1, size, digit_length);
    print_number(number_1, size, digit_length);
    print_number(number_1, size, digit_length);
    
    cout << "End of phase 1...." << endl;
    delete [] number_1;
    
    system("pause");
    return 0;
    
}

void print_number(int num[], int sz, int sz_used)
{
    cout << endl;
    for (int i = 0; i < sz; i++)
        cout << num[i];
}

void new_line()
{
    char symbol;
    do {
        cin.get(symbol);
    }while (symbol != '\n');
}

void get_number (int num[], int sz, int & sz_used)
{
    char symbol;
    sz_used = 0;
    
    cout << "Enter an integer .........." << endl;
    do {
        cin.get(symbol);
        switch (symbol) {
                case '0': case '1': case '2': case '3': case '4':
                case '5': case '6': case '7': case '8': case '9':
                    if (sz_used < sz) 
                        num[sz_used++] = symbol - 48;
                    else {
                        cout << "Overflow .... please re-enter: ";
                        sz_used = 0;
                        new_line();
                    }    
        
        break;
        case '\n': break;
                default: cout << "\nillegal input !!! please re-enter:";
                    sz_used = 0; 
                    new_line();
        }
    } while (symbol != '\n');
}
hi,
I'm not realy shore what your program is supposed to do,
however I found some funny mistakes which may help you figuring out what went wrong,
they are commented out!!

plsae use comments when you write a programs so other can read what you mean while reading your program, at least each function shall have some comment (like what is this function acctualy doing)!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
int main()  {
    int size;
    int digit_length;  //USED BUT NOT INITIALIZED :/
    //int *number_1; //WHAT IS THIS ?? ON THE STACK OR HEAP????
    //int *new_int[0];  //HERE CAN NOT BE NUMBER 0 THIS IS SUPPOSED TO BE AN ARRAY ON THE STACK??
	//IT CAN NOT BE AN POINTER !! IF ON THE STACK?
    
    cout << "phase 1..... " << endl;
    cout << "Enter the size: " << endl;
    cin >> size;
    digit_length = 10;  //ADDED INITIALIZATION (MISSING FOR FUNCTIONS ARGUMENT)
    int* number_1 ( new int[size]);  //moved here from above
    new_line();
    get_number(number_1, size, digit_length); //DIGIT LENGTH NOT INITIALIZED
    print_number(number_1, size, digit_length);  //DIGIT LENGTH NOT INITIALIZED
    print_number(number_1, size, digit_length);  //DIGIT LENGTH NOT INITIALIZED
    
    cout << endl << "End of phase 1...." << endl;
    delete [] number_1;  //YOU'VE TRYED TO DELETE MEMORY ON THE STACK ??
	cout << endl << "finish...";
	cin.ignore();  //REMOVED SYSTEM("PAUSE") cos it's bad :) 
	return 0;
}


well this is the most confusing thig in your program:
int *new_int[0]
I think even god programes can't figure out what this declaration acctualy mean?

cheers!
Last edited on
Topic archived. No new replies allowed.