CAS Community   >   Resources   >  

Coin_throws-01
Program: Heads or Tails x 20

Random coin toss game

Phil Gardner

Created by Phil Gardner
last edited Mar 02 2021 by Phil Gardner



Inspired by Glen Thomas, Michael Kolling et al! (I took a look at the Java version by Michael.)

Several versions of the coin-toss game have been posted on CAS… here’s mine. Well, one of mine.

Run on Raspberry Pi, Apple Mac or Linux PC. Alternatively, paste the code into repl.it using a C++ repl.

Warning! Slight modification needed if you are using CodeBlocks and GNU C++ on a Windows PC - random number function a little different in that version.

Another approach to the program is to use arrays to hold the totals and label the coin, leading to less code. This version goes for readability, hence it has more code than you really need with explicit comparisons to true values etc. when deciding whether to play the game again.

I’ll post the terse version at a later date - more-able students (and their teachers…) should be able to see where you can generalise with arrays or short-circuit evaluations (whilst still retaining readability).

As the program says: “Laters…”

Downloaded 29 times.

Download

This resource has attached files: to access these files, please tick the box below to assent to the license terms
License: The resources on CAS website are under Creative Commons Attribution-Share Alike 3.0 licence unless otherwise specified by the resource creators.

You must confirm that you have read and agree the licence's ToS before you can download the attachments of this resource.

I have read the licence agreement of this resource and agree to abide by its terms and conditions.

Feedback and Comments


Available when logged in (join via the front page, for free):
  • View 0 comments on this resource.
  • View resource history, links to related resources.
  • Leave feedback for the author(s), or help by editing the resource.
Categories:


All Rights Reserved © Computing At School 2021
Using the websiteDisclaimer of liabilityCookies policyPrivacy notice