/* ************************************************************************** * Program name : 044_Two_dice (Version 1.00) * * Author : Duck Wong * * Language : C / C++ * * Compiler : Boodshed Dec-C++ compiler Ver 3.95 * * Computer : PII350 * * O/S : Windows 98 * ************************************************************************** * Version 1.00 : 2000/06/25 - first version * ************************************************************************** * Description : (a) Reset the values of each element to zero * * (b) Repeat asking the number of roll * * (c) Get the roll * * (d) Output the result * * (e) Try again ? * ************************************************************************** */ #include #include #include #include const int Arraysize = 6; int Roll[Arraysize][Arraysize]; void getdice(int Roll[][6], int Times) // Note (1) { int Index; for (Index=1; Index<=Times; Index++) Roll[rand() % 6][rand() % 6]++; } int main() { // part 1 : declaration int Number, Index_1, Index_2; char Again; do { srand(time(NULL)); // part 2 : Reset the values of each element in the array to zero for (Index_1=0; Index_1> Number; } while (Number <= 0); // part 4 : Get the roll getdice(Roll,Number); // Note (1) // part 5 : Output the result cout << "\n\n\t 1 2 3 4 5 6" // Note (2) << "\n\t --------------------------------"; for (Index_1=0; Index_1> Again; cout << "\n"; } while (Again=='Y' || Again=='y'); cout << "\n" << endl; system("PAUSE"); return 0; } /* Notes (1) When we receive a single-subscripted array as an argunebt to a functioin, the array brackets are empty in the function's parameter list. The size of the first subscript of a multiple-subscripted array is not required either, but all subsequent subscript sized are required. Therefore function header becomes : void getdice(int Roll[][6], int Times) And the call statement becomes : getdice(Roll, Number); (2) A table is used to show the number of roll for each combination of dice. Example : How many times do you want ? 6666 1 2 3 4 5 6 -------------------------------- 1 | 202 178 187 187 172 157 2 | 193 191 178 180 204 181 3 | 176 174 179 198 190 191 4 | 198 179 188 174 188 184 5 | 182 201 190 187 174 204 6 | 175 187 193 162 190 192 (3) A summary is used to show the number of roll for the sum of dice. Example : Summary : Sum No. of Roll Sum No. of Roll ------------------ ------------------ 2 202 8 922 3 371 9 759 4 554 10 520 5 737 11 394 6 892 12 192 7 1123 */