Missing return statement in Class

27 Views Asked by At

I'm trying to write a class and it keeps telling me I'm missing a return statement.

public int sum(int num1, int num2) { questions++;

    firstSum = num1;
    secondSum = num2;

    if (firstSum < secondSum)
    {
        while (firstSum != secondSum)
        { firstSum++;}
        return int firstSum;

    }

    if (secondSum < firstSum)
    {
        while (secondSum != firstSum)
        { secondSum++;}
        return int secondSum;

    }

    if (firstSum == secondSum)
    {
        return int firstSum;
    }
}

This part is suppose to be called to add up two numbers inclusively. firstSum and secondSum are defined at the beginning of the class. I can't do void because it won't allow me to call it in the tester.

0

There are 0 best solutions below