61.7k views
0 votes
Write a program to roll a pair of die a random number of times between 1,000 and 10,000 times. Track the sum of the faces of the die for each of the possible sums. Print the results of each pair of die and the sum tallies (possible sums: 2, 3, 4,...12).

I need help writing this program , urgent help

User MothOnMars
by
4.3k points

1 Answer

2 votes

#include <iostream>

#include <ctime>

#include <iomanip>

int main(int argc, char* argv[]) {

std::cout << " 1st\t 2nd\t Tot.\t Ave.\\+-------------------------------+\\";

double first, _first=0, second, _second=0;

srand(time(NULL));

int amount = (rand() % 10000)+1000;

int _amount = amount;

while(amount>0) {

first = (rand() % 6)+1;

_first+=first;

second = (rand() % 6)+1;

_second+=second;

std::cout << " " << int(first) << "\t " << int(second) << "\t " << int(first+second)

<< "\t " << std::fixed << std::setprecision(2) << (first+second)/2 << std::endl;

amount--;

}

std::cout << "\\\\First Average: " << _first/double(_amount) << "\\Second Average: " << _second/_amount

<< "\\Average Total: " << (_first+_second)/double(_amount)<< "\\Total Attempts: " << _amount << std::endl;

return 0;

}

Write a program to roll a pair of die a random number of times between 1,000 and 10,000 times-example-1
Write a program to roll a pair of die a random number of times between 1,000 and 10,000 times-example-2
User Cdesmetz
by
4.0k points