I know I don't have much done, but I am really stuck and my grade does ride on this. I have used this website to write my other problems please help. I know I have the inputof the intergers wrong. and the program is due tomorrow. please help!

//**************************************************************
// *************************************************************
//
//  BigInt.cpp
//
//  This program adds large integers that are stored in arrays.
//  The digits are stored in the array in reverse order so that
//  addition is easier.  The program allows a user to keep doing 
//  more additions as long as he/she wishes.
//
// *************************************************************

#include <iostream>
#include <cctype>
#include <cstdlib>
#include <cstddef>

using namespace std;

typedef int* IntArrayPtr;
const int MAX_SIZE = 20;

void inputBigInt(IntArrayPtr &a, int& sizeA);
// Precondition: The user is ready to enter an integer
// Postcondition: The digits of the integer read in are stored
// in reverse order in the array a and the number of digits is 
// stored in sizeA. Array a will have been dynamically allocated


void outputBigInt(IntArrayPtr a, int sizeA);
// Precondition: a is defined
// Postcondition: The integer represented by a has been output.


void add (IntArrayPtr a, int sizeA, IntArrayPtr b, int sizeB, 
         int& sizeSum);
// Precondition: Parameters a, sizeA, b and sizeB have values.
// Postcondition: The parameter sum contains the sum of the
// integers represented by a and b and sizeSum contains the number of
// digits in the sum. Array sum will have been dynamically allocated.


// ========================
//      main function
// ========================
int main()
{
    IntArrayPtr a;
    IntArrayPtr b;
    IntArrayPtr sum;
    int sizeA, sizeB, sizeSum;
    const int MAX_SIZE = 20;
    char goAgain;   // loop control

    cout << endl;
    cout << "Addition of big integers" << endl << endl;

    do {
        //
        // Get two big integers
        //
        inputBigInt(a, sizeA);
        inputBigInt(b, sizeB);

        //
        // Find the sum and print the result
        //
      //  add (a, sizeA, b, sizeB, sum, sizeSum);
        cout << "The sum of ";
        outputBigInt(a, sizeA);
        cout << " and ";
        outputBigInt(b, sizeB);
        cout << " is ";

        outputBigInt (sum, sizeSum);
        cout << endl << endl;
        cout << "Add two more? (y or n): ";
 
        //
        // Release the memory
        //
        delete[] a;
        delete[] b;
        delete[] sum;

        cin >> goAgain;
    }
    while (goAgain == 'y' || goAgain == 'Y');

    system("pause");
    
    return 0;
}


// =================================
//       Function definitions
// =================================
void outputBigInt (IntArrayPtr a, int sizeA)
{
    //
    // Print the digits in reverse order 
    //
    for (int i = 0; i < sizeA; i++)
        cout << a[sizeA - i - 1];
}


	// --------------------------------
	// ----- ENTER YOUR CODE HERE -----
	// --------------------------------
// Precondition: The user is ready to enter an integer
// Postcondition: The digits of the integer read in are stored
// in reverse order in the array a and the number of digits is 
// stored in sizeA. Array a will have been dynamically allocated
void inputBigInt(IntArrayPtr &a, int& sizeA)
{    
     char* NumberArray;
     NumberArray = new char[MAX_SIZE];
     using namespace std;
     char number;
     cout << "Please enter a number. ";
     cin >> number;
     NumberArray[MAX_SIZE] = number;
     cout << NumberArray[MAX_SIZE];
     cout << endl;
}

void add (IntArrayPtr a, int sizeA, IntArrayPtr b, int sizeB, 
         int& sizeSum){
         
         
              }

	// --------------------------------
	// --------- END USER CODE --------
	// --------------------------------

Recommended Answers

All 3 Replies

I guess my question is...how do i take in chars in the input function, then put them individually in an array, then convert them into intergers in another array.

From char to integer (without checking whether character c is a real digit, you'll have to add that yourself if you want):

short chr2int(char c) {
     return c-'0';
}

From digit to character it's nearly the same, but you'll have to do +'0' instead of -'0' :)

Avoid using system("pause"); (reason), try cin.get() instead ...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.