Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- # include <ctime>
- int moneda()
- {
- int lanzar;
- lanzar= rand() % 2 + 1;
- if (lanzar == 1)
- cout << "Cara!" << endl;
- else
- cout << "Escudo!" << endl;
- return (lanzar);
- }
- int main ()
- {
- int NUM_LANZ;
- double count, lado, cara = 0, escudo = 0;
- cout<<"Cuantas veces quiere lanzar la moneda?"<< endl;
- cin>>NUM_LANZ;
- srand(static_cast<int>(time(0)));
- for (int count=1; count <= NUM_LANZ; count++)
- {
- lado = moneda();
- if (lado == 1)
- cara++;
- else
- escudo++;
- }
- cout << "Cantidad de veces que se lanzó la moneda: " << NUM_LANZ << endl;
- cout << "Porcentaje que resultó cara: " << ((cara / NUM_LANZ) * 100)<<"%" << endl;
- cout << "Porcentaje que resultó escudo: " << ((escudo / NUM_LANZ) * 100)<<"%" << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement