Answer to Question #208171 in C++ for Abende

Question #208171

 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

 

  } 



1
Expert's answer
2021-06-18T02:54:24-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS