Program addition help

Hey Everyone,

I'm quite new to C++ and I'm doing a little assignment right now for school. Basically a program which adds the biggest and middle number when you enter 3 digits in. My program currently works but it will add the biggest and the smallest, I need it the other way around LOL.

I know my code to find the largest works (since it will find the largest no matter what order I enter it), but the code to find the 2nd largest might be my issue.

In my program, for it to find the second largest number I have:


if (num3 < largest)
largest2 = num3;

sum = largest + largest2;

I know the error is somewhere in there, but can't quite pick it out. Where did I go wrong?

Thanks.
Last edited on
use [ code ] [/ code ] tags.

if (num3<largest)

I think you meant to check if the last number is greater than the 2nd largest number. Try:

if (num3>largest2)
Last edited on
Oh no, we're meant to write it so that it finds the largest number, then the 2nd largest... well basically any way so that it finds the largest and second largest. So should it be incrementally where it finds the 2nd largest, then finds one bigger than that?
Oh thanks! I did exactly what you said and it works now.... in the end these tiny errors screw everything up. lol.
Last edited on
Your tellin me... Try looking through 700 lines of code for possible causes of a SegFault.
Topic archived. No new replies allowed.