Advertisement
ItzEdInYourBed

coinflip.cpp

May 14th, 2020
1,136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.34 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <ctime>
  4.  
  5. int main() {
  6.  
  7.   // Create a number that's 0 or 1
  8.  
  9.   srand (time(NULL));
  10.   int   coin = rand() % 2;
  11.  
  12.   // If number is 0: Heads
  13.   // If it is not 0: Tails
  14.  
  15.   if (coin == 0) {
  16.  
  17.     std::cout << "Heads\n";
  18.  
  19.   }
  20.     else {
  21.    
  22.     std::cout << "Tails\n";
  23.  
  24.   }
  25.  
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement