## CCC '06 J2 - Roll the Dice

View as PDF

Points: 3
Time limit: 2.0s
Memory limit: 256M

Problem type
##### Canadian Computing Competition: 2006 Stage 1, Junior #2

Diana is playing a game with two dice. One die has sides labelled .

The other die has sides labelled .

Write a program to determine how many ways can she roll the dice to get the sum .

For example, when the first die has 6 sides and the second die has 8 sides, there are 5 ways to get the sum :

• 2 + 8 = 10
• 3 + 7 = 10
• 4 + 6 = 10
• 5 + 5 = 10
• 6 + 4 = 10

#### Input

The input is given as two integers. First, the user will enter in the number  .

Second, the user will enter the number  .

#### Output

The program prints out the number of ways may be rolled on these two dice. Note that in the output, the word way should be used if there is only one way to achieve the sum of ; otherwise, the word ways should be used in the output. That is, if there is only one way to get the sum , the output should be:

There is 1 way to get the sum 10.

#### Sample Input 1

6
8

#### Sample Output 1

There are 5 ways to get the sum 10.

#### Sample Input 2

12
4

#### Sample Output 2

There are 4 ways to get the sum 10.

• commented on Jan. 20, 2023, 3:13 a.m.

Where is wrong with my code... I've got the sixth input wrong

• commented on Oct. 8, 2022, 12:31 a.m.

If you are having issues : When there is 1 way, it is written : "There is 1 way to get the sum 10." However when there are zero ways or more than 1 way, it is written as :"There are " + ways + " ways to get the sum 10."

• commented on Jan. 11, 2021, 5:49 p.m. edit 3

Just to give you guys some help. When there is 1 way, it suppose to be "There is 1 way" When there is more than 1 way, it suppose to be "There are 4 ways"

• commented on Dec. 23, 2020, 5:49 p.m.

Why does my code fail when the are 0 ways?

• commented on July 26, 2021, 12:03 a.m.

For 0 ways you need to out put "There are 0 ways to get the sum 10."

• commented on Dec. 24, 2020, 4:02 a.m.

Grammar: it's supposed to print

There are 0 ways to get the sum 10.

• commented on Nov. 10, 2019, 1:38 a.m.

Does this problem involve counting 4 + 6 as the same as 6 + 4 even if the numbers are on different dice?

• commented on Nov. 10, 2019, 2:03 a.m.

4 + 6 and 6 + 4 are considered to be different, as described in the problem statement. The problem in your code lies elsewhere -- consider the following test case:

3 11

The expected output is:

There are 3 ways to get the sum 10.
• commented on Sept. 27, 2019, 12:17 a.m.

Watch out, if there is only one way it must be one WAY, if there are more ways, then it has to be WAYS with an s.

• commented on Nov. 19, 2019, 9:06 p.m.

or if there are 0 ways, I forgot to make a value for that and was stuck for a while

• commented on April 2, 2019, 7:17 p.m.

I realized this after doing the code, the test cases don't account for the fact that some of the combinations are identical i.e 6 + 4 = 10 and 4 + 6 = 10!

• commented on Sept. 20, 2020, 3:24 a.m.

This is intentional. In probability, they are considered 2 different outcomes. Consider that rolling a 2, with two fair six sided dice, is less likely to appear than 3 since 3 can be obtained two ways and 2 only one.

• commented on Oct. 15, 2018, 12:45 a.m.

i know i messed up so much because of the grammar. :(

• commented on July 4, 2018, 4:02 p.m.

Did you know that 8!/2/10 = 2016? Figured that out while making an equation for the program

• commented on May 5, 2021, 1:36 a.m.

This comment is hidden due to too much negative feedback. Show it anyway.

• commented on Dec. 22, 2017, 11:24 p.m.

Heck the grammar >:(