CSIT 139 C++ Write a program that 1) throws two dice 2) choose the number that a
ID: 3884063 • Letter: C
Question
CSIT 139 C++
Write a program that
1) throws two dice
2) choose the number that appears on the first die
3) multiply the number by 5
4) add 7 to the product
5) double the sum
6) add this number to the number that appears on the other die
7) subtract 14 from this sum
8) display the difference
9) apply steps 3 to 8 to the second die
In your solution declare the random number generator variables, u and e and only 2 other variables.
Use a single expression to performs steps 3 through 8.
Without parentheses, the expression is
2 x die1 x 5 + 7 + die2 - 14
Explanation / Answer
C++ Program
#include<iostream>
#include<stdlib.h>
#include <ctime>
using namespace std;
int main()
{
//Genarating dice 1 value by using random number genarator(rand()) function.
srand(time(NULL));
int dice1Value=rand()%6 + 1;
cout<<"The Dice1 value is "<<dice1Value<<endl;
//Genarating dice 1 value by using random number genarator(rand()) function.
int dice2Value=rand() % 6 + 1;
cout<<"The Dice2 value is "<<dice2Value<<endl;
//Calculating Result.
int answer=2*(dice1Value*5+7)+dice2Value - 14;
cout<<"Result is "<<answer<<endl;
return 0;
}
OUTPUT :-
The Dice1 value is 3
The Dice2 value is 6
Result is 36
2:-
The Dice1 value is 2
The Dice2 value is 6
Result is 26