please create a C++ program that will ask the user how many times to roll a pair of dice. The choices are 10, 20 & 50. Allow the user to select 1 choice and error if none of the choices are valid. The program will then the desired amount. The program will keep track of the running total of the sum of the dice (i.e. 5, 2 = 7; 3,6 =7+9 = 16). The program will then produce the total sum at the end of the program along with the average number rolled (i.e. 99 / 10 = 9.9 or 10). You must create a function for the for the dice rolling portion and passed the results back to the main function.
#include <iostream>
#include <ctime>
using namespace std;
int rolldice()
{
return (1+rand()%6);
}
void countsandv(int count)
{
int sum=0,average=0;
for (int i = 0; i<count; i++)
{
int dice = (int) rolldice();
sum+=dice;
}
average=sum/count;
cout << "Sum is" << sum<<endl;
cout << "Average is" << average<<endl;
}
int main()
{
cout<<"choices are 10, 20 & 50"<<endl;
int count;
cin>>count;
srand(time(0));
if(count==10)
countsandv(10);
else if(count==20)
countsandv(20);
else if(count==50)
countsandv(50);
else
cout<<"none of the choices are valid"<<endl;
return 0;
}
Get Answers For Free
Most questions answered within 1 hours.