Drill

ProblemsC++ › games

Score a dice pair

easygamesMathC++

Roll two dice and sum them. If the two dice match, the pair doubles in value.

dicePair(firstRoll: int, secondRoll: int) → int

C++ needs a compiler and Drill does not host one yet, so this page is the reference rather than an exercise: the problem, worked examples, and the solution in full. To type it out, the same problem runs in Python.

Solve it in Python →

Where you start

int dicePair(int firstRoll, int secondRoll) {
    
}

Worked examples

CallResult
dicePair(6, 6)24
dicePair(3, 4)7
dicePair(1, 1)4
dicePair(2, 5)7

Hint

Sum first, then check for a double.

Reference solution in C++
int dicePair(int firstRoll, int secondRoll) {
    int sum = firstRoll + secondRoll;
    if (firstRoll == secondRoll) sum *= 2;
    return sum;
}

The same problem in another language

More games problems in C++