Write a C++ program to roll 3 dice, show the values of these dice, and show the total value of these dice.?
I actually did this but I am very sure it is wrong.
Expand|Select|Wrap|Line Numbers
- #include <iostream>
- #include <cstdlib>
- #include <time.h>
- using namespace std;
- int rollDice();
- int main(int argc, char* argv)
- {
- int numRolls;
- int arrRolls[6];
- int dieRoll;
- srand((unsigned)time(0));
- cout << "How many times would you like to roll the dice?" << endl;
- cin >> numRolls;
- for (int k = 0; k < 6; k++)
- {
- arrRolls[k] = 0;
- }
- for (int i = 1; i <= numRolls; i++)
- {
- dieRoll = rollDice();
- cout << "Die Roll " << i << ": " << dieRoll << endl;
- arrRolls[dieRoll - 1]++;
- }
- for (int j = 0; j < 6; j++)
- {
- cout << "The number " << j + 1 << " was rolled " << arrRolls[j] << " times." << endl;
- }
- }
- int rollDice()
- {
- int result;
- result = (rand() % 6) + 1;
- return result;
- }