4 Replies - 256 Views - Last Post: 19 May 2014 - 12:54 PM Rate Topic: -----

#1 StoneyFL  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 12-May 14

Loop

Posted 19 May 2014 - 10:06 AM

What kind of loop would I use to make this program?

Suppose you have one machine; it pays 2 quarters every 3rd play,
Margerie has 4 quarters, and when she arrives the machine has never been played.
Your program output might look like this:
This test case MUST work, and the answer must be 8.

How many quarters does Marge have in the jar? 4
How many times has the machine been played: 0
Lose – 3 left
Lose – 2 left
Win – 3 left
Lose – 2 left
Lose – 1 left
Win – 2 left
Lose – 1 left
Lose - 0 left
Game over. Margerie played 8 times.

Is This A Good Question/Topic? 0
  • +

Replies To: Loop

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9057
  • View blog
  • Posts: 34,001
  • Joined: 12-June 08

Re: Loop

Posted 19 May 2014 - 10:11 AM

A for loop, while loop, or even possibly recursion with no loop. Take your pick.
Was This Post Helpful? 0
  • +
  • -

#3 farrell2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 823
  • View blog
  • Posts: 2,533
  • Joined: 29-July 11

Re: Loop

Posted 19 May 2014 - 10:12 AM

while. You try to figure out the rest.
Was This Post Helpful? 0
  • +
  • -

#4 peepsrct  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 134
  • Joined: 29-March 09

Re: Loop

Posted 19 May 2014 - 10:13 AM

I'd give recursion a go.
Was This Post Helpful? 0
  • +
  • -

#5 jon.kiparsky  Icon User is online

  • Pancakes!
  • member icon


Reputation: 7625
  • View blog
  • Posts: 12,855
  • Joined: 19-March 11

Re: Loop

Posted 19 May 2014 - 12:54 PM

Think about logic before you think about code.

How does this program look in your mind? What steps do you need to take, what decisions do you need to make, and what data do you need to keep track of? Make marks on paper until you start to understand the flow of the thing. That will generally tell you what you need to know.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1