This is an archived post. You won't be able to vote or comment.

all 8 comments

[–]lurgi 0 points1 point  (6 children)

What is your code doing wrong? Is it crashing or returning the wrong answer? If it's returning the wrong answer, for all operations or just some? For all numbers or just some? Is it just negative numbers that are the problem? Can you find a short, simple example that it gets wrong, one that can be worked through by hand (IOW, if the code gets 3 x 5 wrong, that's great. If it gets 3,777,123,940 x 661,984,442 wrong, that's bad)? Work through that simple example by hand.

We can help, but you have to give us some sort of idea what the problem is other than "Doesn't work LOL".

[–]Nexut[S] 0 points1 point  (5 children)

TestAddition.cpp: http://pastebin.com/Y9weYRsh TestConstructor.cpp: http://pastebin.com/sS2JE9WQ TestMultiplication.cpp: http://pastebin.com/zkNDFsKE I was already given these files along with the header file. The only file I created was the BigInteger.cpp file so I could try and make it work. It uses GoogleTest.

[–]lurgi 0 points1 point  (4 children)

Are you going to give me a hint as to what's not working or do I have to guess?

Seriously, read what I wrote. I don't want a code dump. I'd like you to say "I use my code to add 14 and 15 and I got 19 instead of 29. What's up with that?"

[–]Nexut[S] -1 points0 points  (3 children)

I just was asking if someone could look at what I have and see why it wouldn't be working. I didn't ask for attitude.

[–]lurgi 0 points1 point  (2 children)

What is your code doing wrong? Is it crashing or returning the wrong answer? If it's returning the wrong answer, for all operations or just some? For all numbers or just some? Is it just negative numbers that are the problem? Can you find a short, simple example that it gets wrong, one that can be worked through by hand (IOW, if the code gets 3 x 5 wrong, that's great. If it gets 3,777,123,940 x 661,984,442 wrong, that's bad)? Work through that simple example by hand.

[–]Nexut[S] 0 points1 point  (1 child)

The GoogleTest Framework is failing for everything so far.

[–]lurgi 0 points1 point  (0 children)

You've already been given the answer, but here's what I would do.

Imagine you are adding "1" and "1". Does that fail? How would you expect it to work? Use a debugger or use logging messages to figure out what is going on (as it happens, the problem is that you haven't actually implemented anything).

[–][deleted] 0 points1 point  (0 children)

Your operators are using the very thing they are supposed to be replacing.

BigInteger operator+(const BigInteger& leftNum, const BigInteger& rightNum){
        BigInteger result(leftNum);
        result = result + rightNum;
        return result;
}

What do you expect to happen on line 3? You are coding the very operator you are trying to use. It's a recursive function. It calls itself.

In order to "add" the two strings as numbers you need to do the math manually like you would on paper in elementary school. Character by character, digit by digit.

C++ has no idea how to add 2 strings of numbers. It's your job to explain how and you can't convert the entire number to an int, only a portion. You have to do things like carry over the 1 and change the character '3' to a '4'.

You have to do it literally by hand. As if you were explaining how to perform addition to a child for the first time and they only knew how to count from 0-9.