Write a program to calculate the probability of getting two six out of 1 thousand times on rolling two dice.
**The teacher gave us a hint by giving a part of the code**
#include <iostream>
#include "time.h"
using namespace std;
int main()
{
srand (time(NULL)); // to introduce different random numbers each run
// Complete
}
#include <iostream>
#include "time.h"
using namespace std;
int main(){
srand(time(NULL)); // to introduce different random numbers each run
int d1, d2;
float freq = 0, prob;
for(int i = 0; i < 1000; i++){
d1 = rand() % 6 + 1;
d2 = rand() % 6 + 1;
if(d1 == 6 && d2 == 6) freq++;
}
prob = freq / 1000;
cout<<"Probability of getting two six: "<<prob;
return 0;
}
Comments
Leave a comment