Random coin toss game
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…”