Question: The code below should allow a user to enter a number for the number of sides of a die. It should then generate a random
The code below should allow a user to enter a number for the number of sides of a die. It should then generate a random number that was rolled on that die. I have stubbed out most of the code. Your job is to complete it.
/* This program allows a user to roll a die of any size. */ #includeusing namespace std; int main() { int numberOfSides = 0; do { cout << "How many sides do you want the die to have? "; cin >> numberOfSides; if (numberOfSides <= 0) { cout << "Error: Please enter a positive integer!" << endl << endl; } } while (numberOfSides <= 0); int result = rollDie(numberOfSides); cout << "You rolled a " << result << endl; } int rollDie(int numberOfSides) { // Complete this function }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
