Replace this: //sort n1 and n2 so that a1 is the largest of n1 and n2. a2 is the least.
if (n1 >= n2)
{
a1 = n1;
a2 = n2;
}
else
{
a1 = n2;
a2 = n1;
}
//if both a1 and a2 are zero then sum is zero
if (a1 == 0)
{
if (a2 == 0)
sum = 0;
}
//if a2 is zero then sum is a1
if (a2 == 0)
sum = a1;
//if a1 is nine and a2 is not zero then sum is a2 minus one
if (a1 == 9)
{
if (a2 != 0)
{
sum = (a2 - 1);
count++;//carry the 10
}
}
//if a2 is greater than or equal to ten minus a1, which equals i,
//then a2 minus i is the sum.
//if a2 is not greater than or equal to ten minus a1
//then sum is a1 plus a2.
//the above logic takes care of all nine plus any number combinations
//thus if a1 is nine this block of code does not need to be run.
//this also prevents the carry of 10 being counted twice.
if (a1 != 9)
{
i = (10 - a1);
if (a2 >= i)
{
sum = a2 - i;
count++;//carry the 10
}
else
sum = a1 + a2;
} with this: Hope this helps :-)
__________________
Few people deserve to be compared to (Rush) Limbaugh, most of them were convicted at the Nuremburg trials.
--WilliamSChips on Slashdot
Last edited by uman; Jun 2nd, 2006 at 12:18 AM.
|