Your code prints the correct result, but doesn't iterate over all the cards correctly. a
and c
should loop up to 52. The extra hands need to be removed with an if
statement:
for (int a = 0; a < 52; ++a) {
for (int b = a + 1; b < 52; ++b) {
for (int c = 0; c < 52; ++c) {
for (int d = c + 1; d < 52; ++d) {
if (c != a && c != b && d != a && d != b) {
total++;
}
}
}
}
}
This can then be modified to eliminate the duplicate hands:
for (int a = 0; a < 52; ++a) {
for (int b = a + 1; b < 52; ++b) {
for (int c = a + 1; c < 52; ++c) {
for (int d = c + 1; d < 52; ++d) {
if (c != b && d != b) {
total++;
}
}
}
}
}