I have been trying to do this assignment for the past 4 days. I thought I was doing good but the functions seem to be screwing up. All the greater than and less than functions are messing up. Also the add and subtract functions are messed up. Any suggestions would be appriciated. Please help me and thanks in advance for those that do.
bool HugeInteger::isGreaterThan(HugeInteger a)
{
for (int i=0; i<40; i++)
{
if (digits[i] < a.digits[i] )
return false;
}
return true;
}
bool HugeInteger::isLessThan(HugeInteger a)
{
for (int i=0; i<40; i++)
{
if (digits[i] > a.digits[i] )
return false;
}
}
bool HugeInteger::isGreaterThanOrEqualTo(HugeInteger a)
{
if (isEqualTo(a)==true)
return true;
for (int i=0; i<40; i++)
{
if (digits[i]<a.digits[1])
return false;
}
return true;
}
bool HugeInteger::isLessThanOrEqualTo(HugeInteger a)
{
for (int i=0; i<40; i++)
{
if (digits[i]>a.digits[i])
return false;
}
}
int HugeInteger::add(HugeInteger a)
{
int flag =0;
int sum[40];
for (int i=39; i>=0; i--)
{
sum[i] = digits[i] + a.digits[i];
if ( sum[i] >= 10)
{
flag=1;
sum[i-1]=sum[i-1]+flag;
}
}
if (digits[0]+a.digits[0]>9)
{
cout << "Error. The sum is too big for the array." << endl;
}
else
return sum[40];
}