Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
CCC 2000 Stage1: S1J3: Slot Machines
Author Message
Tony

Posted: Sat Feb 08, 2003 2:29 pm   Post subject: CCC 2000 Stage1: S1J3: Slot Machines

Solution to 1st Senior program (3rd on Junior level) writen in C++.
--------------------------------------------------------------------------------

Martha takes a jar of quarters to the casino with the intention of becoming rich. She plays three machines in turn. Unknown to her, the machines are entirely predictable. Each play costs one quarter. The first machine pays 30 quarters every 35th time it is played; the second machine pays 60 quarters every 100th time it is played; the third pays 9 quarters every 10th time it is played.

Your program should take as input the number of quarters in Martha's jar (there will be at least one and fewer than 1000), and the number of times each machine has been played since it last paid.

Your program should output the number of times Martha plays until she goes broke.

Input/output is not from/to files for this question. Keyboard input and screen output is expected.

Sample Session. User input is in italics
How many quarters does Martha have in the jar?
48

How many times has the first machine been played since paying out?
3

How many times has the second machine been played since paying out?
10

How many times has the third machine been played since paying out?
4

Martha plays 66 times before going broke.
--------------------------------------------------------------------------------

Some Notes:

The solution is quite simple. You just run a loop simulating the casino where 3 machines are played in turn (1st - 2nd - 3rd - back to 1st). You count how much each machine is played (remember that all machines were played by other people before, so don't start from 0)

You should also keep in mind that she CANT borrow some quaters to compleat the turn... such as if she has 1 quater left, she plays 1st machine, and not 2nd and 3rd unless 1st machine pays on that turn.

In my solution the final output is the counter of plays + jar because if she gous into negative coin amount those plays shouldn't count.

See file attached for solution.

source.cpp
Description:
 updated source file for 2000 S1J3 problem

Filename:  source.cpp
Filesize:  952 Bytes

Tony's programming blog. DWITE - a programming contest.

Dan

Posted: Mon Feb 24, 2003 9:31 am   Post subject: turing version

i was studying some of thess expame question and i tested my self by making a turing version of this progame with out looking at the solution. i atcuched my slotion. i lefted out erro cheking the input for the user input in this one.

hey tony tell me what you think, i cheked it with the data form sample run and it wroked so i think it is right.

ccc.t
Description: