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];
}

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.

Start over.
Write the input section of the program first. Get it to work.
Then the output section. Get it to work.
Add 1 and only 1 function. Get it to work.
Add one more function. You can probably base it on the first function since that one works.

Continue....

Start over.
Write the input section of the program first. Get it to work.
Then the output section. Get it to work.
Add 1 and only 1 function. Get it to work.
Add one more function. You can probably base it on the first function since that one works.

Continue....

I have an output function that is how I know that the functions are not working.
what I don't have is the knowledge to know why these are not working, people on here are just like my teacher, they think answers are just going to pop into your head all of the sudden. I have been trying to do this for like 5 hours each day for the last 4 days. Probably like 8 today. That is why I tried to expand my number of resources and ask for help. But everyone just says to figure it out. I have tried this stuff so many wrong ways even when I get the right way it won't matter because it will just be another answer stored away with 100 of wrong ways. Most people learn things by being taught. Kinda like why I do better in Math classes, because if I ask my teacher how to work a problem she will show the way and not just turn you away confused.

First of all, how do you store your huge number?
From what I see, you store number in array of integer. digits[40] . First digit of the number is stored at the last element of the digit array. However, for example: number 49. Will it store this way:

digit[]	0  1  2  3  4  5  6  7  8  9		38 39
value	0  0  0  0  0  0  0  0  0  0 ...	 4   9

or

[i]u = undefined[/I]
digit[]	0  1  2  3  4  5  6  7  8  9		39 39
value	u  u  u  u  u  u  u  u  u  u ...	 4   9

I don't think you have provided enough information. At least provide us some error message or examples of incorrect output.

I have an output function that is how I know that the functions are not working.
what I don't have is the knowledge to know why these are not working, people on here are just like my teacher, they think answers are just going to pop into your head all of the sudden. I have been trying to do this for like 5 hours each day for the last 4 days. Probably like 8 today. That is why I tried to expand my number of resources and ask for help. But everyone just says to figure it out.

I never said "just says to figure it out." you are getting confused because you aren't sure what you are doing and you're trying to to 10 things 10 different ways at once. That's why I said

  • do 1 function.
  • we can help with 1 function
  • you get it correct,
  • you understand that one function
  • the rest are easy

That's teaching. But why you think we are here to teach is beyond me. We're here to help, not teach.

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.