Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*6.33 Coin Tossing
- Deitel & Deitel C++ How to Program, 10th ed (Indian subcontinent adaptation)
- Visual Studio Community 2019
- */
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- int coinToss(void) {
- return (1 + rand()) % 2;
- }
- int main() {
- srand(static_cast<unsigned int>(time(0)));
- int heads{ 0 };
- int tails{ 0 };
- for (int i = 0; i < 100; i++) {
- if (coinToss() == 1) {
- cout << "Heads" << endl;
- heads++;
- }
- else {
- cout << "Tails" << endl;
- tails++;
- }
- }
- cout << endl << "Final tally:" << endl << endl;
- cout << "\t Heads " << heads;
- cout << "\t Tails " << tails << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement