Hi, I have been working on this program for a while, and it is just getting plain frustrating. I'm trying to make a class(called numberType) which can take a number with up to 100 digits using a 100 integer character array and then be able to add that class with another one.
To do this, I made a class function that takes the number you give it, and reverses the order as shown below so that I can later on add two classes together.
void numberType::setNumber(int number)
{
for (int i = 0; num[i] != -99; i++)
{
num[i] = (number % 10);
number = number / 10;
if (number == 0)
{
num[i+1] = -99;
}
}
}
num[] is the 100 character array that I am using. In the code I also use the number "-99" as a form of a null character so that when it hits that number in my array, it will stop printing.
My problem however is I can do everything except shift the numbers over 1 value if two numbers added together is larger than 9. For instance, if I have one numberType of 500, and another of 400, it will be displayed as 009, but I try to add 500 + 500, it does not display the desired result of 0001. Even more, I've been trying to make it so that it stops once it reaches a -99 value, but it just won't cooperate and adds them anyways. Gah, now I'm talking to my code as if it was some sort of retarded monkey.
Here's the function that is driving me bonkers. If you could help me why this darn thing isn't doing what I want it to do, I'd gladly appreciate it.
numberType numberType::operator+
(const numberType& number) const
{
numberType temp;
for (int i = 0; temp.num[i] != -99 && i < 100; i++)
{
temp.num[i] = num[i] + number.num[i];
if (temp.num[i] >= 10)
{
temp.num[i] = temp.num[i] - 10;
if (temp.num[i+1] == -99)
{
temp.num[i+1] = 1;
temp.num[i+2] = -99;
}
else
{
temp.num[i+1] += 1;
}
}
}
return temp;
}