princeton egg eas230

princeton egg eas230 - "...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
#include <iostream> #include <cstdlib> #include <ctime> #include <cmath> int main() { int coinFlips = 0; //no. of coin flips; int randomNumber = 0; // result of rand num generator int numberOfHeads = 0, numberOfTails = 0; int signOfTrouble = 0; double percentage = 0.0; srand( (int)time(0) ); // flip 10000 coins for (coinFlips = 1; coinFlips <= 10000; coinFlips++) { // generate a random number 0-9 randomNumber = rand()%10; // if it's 5 or greater, count as a head if (randomNumber >= 5) { numberOfHeads++; } // 4 or less, count as a tail else { numberOfTails++; } cout<< randomNumber << "
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: &quot; &lt;&lt; numberOfHeads &lt;&lt; &quot; &quot; &lt;&lt; numberOfTails &lt;&lt; endl; } // this refelcts the number of coin tosses that stray from 50/50 signOfTrouble = abs(numberOfHeads - numberOfTails)/2; cout &lt;&lt; signOfTrouble &lt;&lt; endl; // as a percentage of total coin tosses. .. percentage = ((double)signOfTrouble / (double)coinFlips) * 100.00; cout &lt;&lt; percentage &lt;&lt; endl; // if greater than 10%, trouble ahead if (percentage &gt; 10.0 ) { cout &lt;&lt; &quot;Go to the basement&quot; &lt;&lt; endl; } else { cout &lt;&lt; &quot;Everything is cool, go to school&quot; &lt;&lt; endl; } } // end program...
View Full Document

Page1 / 2

princeton egg eas230 - &amp;amp;quot;...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online