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)
#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;
}
}
Comments
Leave a comment