Name: ________________________________

Honor Code Acknowledgment: _____________________________


CPS 6, Summer 1999                 Random Quiz 4

Due: Monday, May 31, 1999                 12 points


Problem: Rolling Unique Numbers (6 pts)

Write the function NumberUnique to print the roll of three 6-sided dice and to return the number of unique numbers rolled.

For example, if NumberUnique printed out:

   Three values rolled are: 6 2 3

then NumberUnique() would return 3 since three unique values were rolled.

If NumberUnique printed out:

   Three values rolled are: 4 2 4

then NumberUnique() would return 2 since two unique values were rolled, 2 and 4.

Complete the function NumberUnique below.

int NumberUnique()
// postcondition: Prints the values rolled of three dice  and
//                returns the number of unique numbers rolled.
{



















Problem: How Many Times Have I Seen You (6 pts)

Write the function CountAppearances to return the number of times a digit appears in a number.

For example, CountAppearances(56854, 5) returns 2 since the digit 5 appears twice in 56854.

CountAppearances(753476, 2) returns 0 since the digit 2 does not appear in 753476.

Hint: Use a while loop. Strip digits off of the number, comparing each digit.

Complete the function CountAppearances below.

int CountAppearances(int number, int digit)
// precondition: digit is a nonzero digit: 1, 2, 3, 4, 5, 6, 7, 8, or 9
//               number is greater than 0 
// postcondition: returns the number of times digit appears in number,
//                returns 0 if digit does not appear in number
{