This is for C thank you in advance 13 Create a function that

This is for C++. thank you in advance!

13) Create a function that will simulate rolling a standard die (d6) and return the result:

Solution

Die.cpp

#include <iostream>
#include <cstdlib>
#include <ctime>   
using namespace std;
int getRollResult();
int main()
{
cout<<\"Standard die (d6) roll result is \" << getRollResult()<<endl;

return 0;
}
int getRollResult(){
srand (time(NULL));
int result = rand() % 6 + 1;
return result;
}

Output:

sh-4.3$ g++ -std=c++11 -o main *.cpp                                                                                                                                                                                        

sh-4.3$ main                                                                                                                                                                                                                

Standard die (d6) roll result is  5                                                                                                                                                                                         

sh-4.3$ main                                                                                                                                                                                                                

Standard die (d6) roll result is  6                                                                                                                                                                                         

sh-4.3$ main                                                                                                                                                                                                                

Standard die (d6) roll result is  4                                                                                                                                                                                         

sh-4.3$ main                                                                                                                                                                                                                

Standard die (d6) roll result is  3                                                                                                                                                                                         

sh-4.3$ main                                                                                                                                                                                                                

Standard die (d6) roll result is  1   

This is for C++. thank you in advance! 13) Create a function that will simulate rolling a standard die (d6) and return the result:SolutionDie.cpp #include <i

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site