• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

flipping coin program

 
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


i have been working on this code that tells that gives a random number and interprets it as a heads or tail on a coin and therefore predicts the probability of a 50/50 chance. the only problem is that i need to add something to the code to where it will automatically tell me how many heads and how many tells it returns. thank you in advance for any help.
 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Nathan,

You can use a variable for example headCount and increment it every time a head is flipped. With this and the flip count you know the number of heads and tails.
 
nathan gibson
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i think i get what you are saying, but my problem is that i really dont know how to translate that into code that will work with my program. im a beginner, sorry.
 
Miklos Szeles
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No problem, we are here to help beginners.

You can do this like this:

 
nathan gibson
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


it still isnt quite working correctly. im sure it is my own fault for making this more difficult than it is, but the program is supposed to ask me for the number of flips, it is supposed to output something like this,
Program Output
 
Miklos Szeles
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just think about what you want. You wolud like to write out whether a tail or a head is flipped and you wolud like to write out the random number for every flip. But what about the number of tails and number of heads? Do you really want to print them out after every flip? I don't think so. So the only thing to do is to put the code which prints the number of heads and tails to the end of the program.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic