Advertisement
Primitiv0

Coin Flip

Sep 10th, 2019
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. # include <ctime>
  4.  
  5. int moneda()
  6. {
  7.     int lanzar;
  8.     lanzar=  rand() % 2 + 1;
  9.                 if (lanzar == 1)
  10.                 cout << "Cara!" << endl;
  11.                 else
  12.                 cout << "Escudo!" << endl;
  13.     return (lanzar);
  14. }
  15.  
  16. int main ()
  17. {
  18.     int NUM_LANZ;
  19.     double count, lado, cara = 0, escudo = 0;
  20.    
  21.     cout<<"Cuantas veces quiere lanzar la moneda?"<< endl;
  22.     cin>>NUM_LANZ;
  23.    
  24.     srand(static_cast<int>(time(0)));
  25.    
  26.     for (int count=1; count <= NUM_LANZ; count++)
  27.      {
  28.         lado = moneda();
  29.         if (lado == 1)
  30.             cara++;
  31.          else
  32.             escudo++;
  33.      }
  34.  
  35.      cout << "Cantidad de veces que se lanzó la moneda: " << NUM_LANZ << endl;
  36.      cout << "Porcentaje que resultó cara: " << ((cara / NUM_LANZ) * 100)<<"%" <<  endl;
  37.      cout << "Porcentaje que resultó escudo: " << ((escudo / NUM_LANZ) * 100)<<"%" <<  endl;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement