{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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 Document Right 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: " << numberOfHeads << " " << numberOfTails << endl; } // this refelcts the number of coin tosses that stray from 50/50 signOfTrouble = abs(numberOfHeads - numberOfTails)/2; cout << signOfTrouble << endl; // as a percentage of total coin tosses. .. percentage = ((double)signOfTrouble / (double)coinFlips) * 100.00; cout << percentage << endl; // if greater than 10%, trouble ahead if (percentage > 10.0 ) { cout << "Go to the basement" << endl; } else { cout << "Everything is cool, go to school" << endl; } } // end program...
View Full Document

{[ snackBarMessage ]}

Page1 / 2

princeton egg eas230 - "<<...

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

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