Task:
Suppose the default number is 10. You are supposed to write a program that outputs the total number of possible addition pairs of integers. Input two integers a and b. The range of both integers will be 1 to a and 1 to b. For example, a=6 and b=8, then there are 5 possibilities.
2+8=10
3+7=10
4+6=10
5+5=10
6+4=10
cannot be 7+3=10 because repeated
cannot be 8+2=10 because repeated
cannot be 9+1=10 because it overflow the range
EXAMPLE 1:
input: 6
8
output: 5 //5 possibilities
EXAMPLE 2:
input: 12
4
output: 4 //4 possibilities
EXAMPLE 3:
input: 1
9
output: 1 //1 possibility
After line 14, the output should be an integer >=0. However, my output is always 0. May some skilled people please help me with the code? Thank you.
your for loop sustenance condition (fsum==fdice) is wrong. It means that the loop will be terminated as soon as fsum != fdice which will be true in most cases, especially since you are modifying fsum within your loop.
well one possible "inefficient" solution is to loop 'i' from 1 to 10 and for each i you check whether the following conditions hold true:
i <= a
i <= b
10 - i <= a
10 - i <= b
and increment a counter accordingly.