for example if i enter into the cin portion 12345 the rest gets filled in with zerosso it looks like
12345000000000000000 i need to revers it so it looks like 00000000000000012345. That way I can repeat my code to enter and add my arrays together wit the unwritten add function
#include <iostream>
#include <cctype>
using namespace std;
//function prototypes
void inputNumber(int _num[], int &_size); //allows user to input # and deter size.
void initialize(int number[], const int size); // initializes any array to 0
void shift(int number[], const int size); //moves number to the end of the array
bool add(const int num1[],const int num2[], int sum[], const int size);//adds the numbers
void display(const int number[], const int size);//displays the arrays
//global constants
const int MAX = 20;
int main()
{
int num1[MAX];
int num2[MAX];
int sum[MAX];
int size1, size2;//tells what position the last significant digit is
initialize(num1, MAX);
inputNumber(num1, size1);
shift(num1, size1);
display(num1, MAX);
return 0;
}
//////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
void inputNumber(int _num[], int &_size)
{
char ch, quit='n', flag='f';
_size=0;
do {
if(_size>=MAX)
flag='t';
cin.get(ch);
if(isdigit(ch))
_num[_size++]= ch - 48;
else
quit='y';
}while(quit!='y');
if(flag=='t')
_size =-1;
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
//I dont see the need for this function if I were to initialize the arrays in main
void initialize(int number[], const int size)
{
for (int x=0; x<MAX; x++)
number[x]= 0;
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
void display(const int number[], const int size)
//dont see why I need to have the const int size
{
for (int x=0; x<MAX; x++)
cout<<number[x];
}
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
void shift(int number[], const int size)
{
int temp, temp2;
for (int x=0;x<MAX;x++)
{
temp=number[x];
temp2=number[MAX];
number[MAX-size]=temp;
}
}

New Topic/Question
Reply




MultiQuote





|