35.7k views
11 votes
Higher Order Functions used for simulations of dice rolls. Definition: An n-sided dice function takes no arguments and always returns an int from 1 to n, inclusive. Types of n-sided dice functions: - Randomized: a randomized dice function can be fair, meaning that ir produce each possible outcome from 1 to n with equal probability. Examples: four_sided, six_sided - Deterministic: a deterministic dice function will be used for testing. Deterministic test dice functions always cycle through a fixed sequence of n values. - We write a make_fair_dice higher-order function to return a fair, randomized n-sided dice function. - We write a make_test_dice higher-order function that will return a deterministic, testing n-sided dice function.

User Aiolias
by
5.7k points

1 Answer

6 votes

Answer:

#include <iostream>

#include <time.h>

#include <string>

using namespace std;

int main(){

srand(time(NULL));

cout<<"Throw dice"<<endl;

int b =0;

int a=0;

a=rand()%6;

b=rand()%6;

for (int i =0;i<1;i++)

{cout<<"dice one: "<<a<<endl;}

for (int i =0;i<1;i++)

{cout<<"dice two: "<<b<<endl;}

if(a>b)

{cout<<"first dice won"<<endl;}

if(b>a)

{cout<<"second dice won"<<endl;}

else{cout<<"they are same"<<endl;

return main();

}

return 0;

}

Step-by-step explanation:

/*best dice roll game just for you change it as you want but all necessary things are there/*

User Heystewart
by
5.7k points