#include #include //This is under construction. void input(int& number, int& number_out_of); void combine(int number, int number_out_of); void permut(int number, int number_out_of); long factorial(int argument); void main() { int x, y; char ans, go_on; cout << "WARNING: This program cannot handle numbers larger than\n"; cout << "12 due to the huge size of factorials.\n"; do{ cout << "Permutations(p) or combinations(c)? -->"; cin >> ans; switch(ans) { case 'c': case 'C': input(x,y); combine(x,y); break; case 'p': case 'P': input(x,y); permut(x,y); break; default: cout << "Invalid response.\n"; } cout <<"\nDo it again?(y/n) -->"; cin >> go_on; }while(go_on == 'y' || go_on == 'Y'); return; } void input(int& number, int& number_out_of) { cout << "Input number of slots: -->"; cin >> number_out_of; cout << "Input number of objects: -->"; cin >> number; if(number_out_of > number || number_out_of <= 0 || number <= 0) { cout << "Try again.\n"; input(number, number_out_of); } return; } void combine(int number, int number_out_of) { long x, y, z, answer; x = factorial(number); y = factorial(number_out_of); z = factorial(number - number_out_of); answer = x/(y*z); cout << "\nThere are " << answer << " combinations.\n"; return; } void permut(int number, int number_out_of) { long x, y, answer; x = factorial(number); y = factorial(number - number_out_of); answer = x/y; cout << "\nThere are " << answer << " permutations.\n"; return; } long factorial(int argument) { long product = 1; while(argument > 0) { product = argument * product; argument--; } return product; }