Please help me with this problem Write a cc program that req
Please help me with this problem!
Write a c++/c program that requests a number that is a positive integer, n. Then simulate the rolling of a pair of dice n times. Print out each simulated roll on a new line along with the sum of the numbers shown on each die. If the computer rolls “1 1”, also print “Snake eyes!” on the same line. Don\'t use an array!
For example:
Enter a positive integer: 4
Roll #1: 3+4 = 7
Roll #2: 5+6 = 11
Roll #3: 6+2 = 8
Roll #4: 1+1 = 2
Snake eyes!
Solution
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
/* initialize random seed: */
srand (time(NULL));
int n;
cout << \"Enter a positive integer: \";
cin >> n;
for(int i=1; i<=n; i++){
int dice1 = rand() % 6 + 1;
int dice2 = rand() % 6 + 1;
cout<<\"Roll #\"<<i<<\": \"<<dice1<<\" + \"<<dice2<<\" = \"<<dice1+dice2<<endl;
if(dice1 == 1 && dice2 == 1){
cout<<\"Snake eyes!\"<<endl;
}
}
return 0;
}
Output:
sh-4.2$ g++ -o main *.cpp
sh-4.2$ main
Enter a positive integer: 4
Roll #1: 6 + 6 = 12
Roll #2: 3 + 6 = 9
Roll #3: 4 + 3 = 7
Roll #4: 4 + 1 = 5
sh-4.2$ main
Enter a positive integer: 4
Roll #1: 3 + 4 = 7
Roll #2: 5 + 1 = 6
Roll #3: 5 + 6 = 11
Roll #4: 5 + 5 = 10

