Answer to Question #272902 in C++ for Mirko

Question #272902

Roll a die from N faces M times and count how many times face X came out (N, M and X chosen by the user)


1
Expert's answer
2021-11-29T00:00:11-0500
#include <iostream>
#include <cstdlib>


using namespace std;


int rollDie(int N, int M)
{
    int roll;
    roll = rand() % (M - N + 1) + N;
    return roll;
}


int main()
{
    int N,M,X;
    cout<<"\nEnter N: ";
    cin>>N;
    cout<<"\nEnter M: ";
    cin>>M;
    cout<<"\nEnter X: ";
    cin>>X;
    srand(time(0));
    for(int i=0;i<X;i++)
    {
        cout << rollDie(N,M) <<endl;
    }
}

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