*edit
Fixed line 5 accidentally put value += value;
Instead of *this += *this;
**edit wasn't thinking when i said *this += *this.
I need a temp value for the orig and then add that each time I fixed but is this a viable method for multiplication or would it be better to do it like we do on paper?
***edit
whoops forgot about the initial so it would be < rhs-1 or just use temp variable to modify like this
Oh alright and one more question can you help me better my < operator
It seems to not work all the time.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
booloperator<( const Integer &lhs , const Integer &rhs )
{
if( lhs == rhs ) return( false ); //lhs is not less than rhs since they are equal
if( lhs.value.size() != rhs.value.size() ) return( lhs.value.size() < rhs.value.size() ); //if lhs length is greater than rhs lhs then it is not less than. ( 100 > 99 ) since 100 has 3 digits and 99 has 2 digits.
auto lhs_it( lhs.value.cbegin() ) , rhs_it( rhs.value.cbegin() ); //const iterators
//the two integers are the same number of digits
while( lhs_it != lhs.value.cend() ) //loop tlll end of lhs integer
{
if( *lhs_it < *rhs_it ) return( true ); //compare from left to right if the right digit is greater than return true since that means the left is smaller
//if they are equal or the lhs is greater return nothing since we must check all of them from left to right.
++lhs_it;
++rhs_it;
}
return( false ); //they are equal so return false since if they are equal lhs is not less than rhs
}
You don't really need your check on line 3. Take a look at your comment on line 15.
I don't really know what is wrong with your while loop, because it would depend on whether or not you are storing the integer's digits/sections in reverse order or not.
Also, std::string (based on your original post) already has overloaded comparison operators you can use instead of doing it manually (Of course, this would not be true if you actually meant to iterate from back to front).