1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
musickatia [10]
3 years ago
10

21. Dice Game Write a program that plays a simple dice game between the computer and the user. When the program runs, a loop sho

uld repeat 10 times. Each iteration of the loop should do the following: • Generate a random integer in the range of 1 through 6. This is the value of the computer’s die. • Generate another random integer in the range of 1 through 6. This is the value of the user’s die. • The die with the highest value wins. (In case of a tie, there is no winner for that particular roll of the dice.) As the loop iterates, the program should keep count of the number of times the computer wins, and the number of times that the user wins. After the loop performs all of its iterations, the program should display who was the grand winner, the computer or the user.
Computers and Technology
1 answer:
Brrunno [24]3 years ago
5 0

Answer:

See Explanation Below

Explanation:

// Program is written in C++ programming language

//.. Comments are used for explanatory purposes

// Program starts here

#include<iostream>

#include <stdlib.h>

#include <time.h>

using namespace std;

int main()

{

int computerWins = 0, computerPlay = 0;

int userWins = 0, userPlay = 0;

int tiedGames = 0;

// Computer Play

for (int play = 0; play< 10; play++) {

   computerPlay = rolls();

   userPlay = rolls();  

   // Check who wins

//Clear Screen

System("CLS")

   if (computerPlay == userPlay) {

       tiedGames++;

cout<<"Ties........" + tiedGames;    }

else {

       if (computerPlay> userPlay) {

           computerWins++;

cout<<"Computer...."<< computerWins;

       } else {

           userWins++;

cout<<"User........"<< userWins;

      }

  }

}

return 0;

}

int rolls() {

srand((unsigned)time(0));

return rand() % 6 + 1;

}

You might be interested in
Assuming that we only support BEQ and ADD instructions, discuss how changes in the given latency of this resource affect the cyc
sertanlavr [38]

Answer:

Refer below.

Explanation:

Because we are inserting commands to beq, we will need an execution of the ALU, and then a register write. This result in and increase cycle time of the PC relative branch:

440+90=530ps.

As it is the longest time to execute, so its a critical path

6 0
3 years ago
Write a method called all Less that accepts two arrays of integers and returns true if each element in the first array is less t
GaryK [48]

Answer:

The program to this question can be given as:

Program:

#include<iostream> //header file

using namespace std; //using name space

bool allLess (int arr1[], int arr2[]) //defining method allLess  

{

int a,b; //define variable

a=  *(&arr1 + 1) - arr1; //hold length of arr1

b=  *(&arr2 + 1) - arr2; //hold length of arr2

if(a!=b) //checking condition  

{

return 1; //return value

}

for(int i=0; i<a; i++) //loop

{

if( arr1[i]>=arr2[i]) //checking condition

{

return 1; //return value

}

}

return 0; //return value

}

int main() //define main method.

{

   int arr1[]={1,2,3,4,5}; //define array arr1 and assign value.

   int arr2[]={4,5,6,7,8}; //define array arr2 and assign value.

   cout<< allLess(arr1,arr2); //function calling

   return 0;

}

Output:

1

Explanation:

The Explanation of the C++ language program can be given as follows:

  • In the above program firstly we include the header file. Then a method is defined that is "allLess" this method accepts two arrays that are "arr1 and arr2". This function returns a boolean value that is true or false.
  • Inside a function, we define a conditional statement and a loop in the if block we check the length of the arr1 array variable is not equal to arr2 array length. if this condition is true it will return false.
  • In the loop, we define another if block in this block we check that if arr1 array elements are grater then equal to arr2 array element if this condition is true it will return false. At the end of both if block and loop the function will return a value that is "true".
  • In the main method, we define two arrays and pass to the function and use (cout function) for print return value.
8 0
3 years ago
Which common online presentation medium do people use to present their own articles?
Nutka1998 [239]
A: news portal hope this helps
7 0
2 years ago
Read 2 more answers
Shawn thought that the screen of the block-based program he was using was
Alja [10]

Answer:

Interface

Explanation:

Definition- "The interface of a particular piece of computer software is its presentation on the screen and how easy it is to operate. <em>...the development of better user interfaces.</em>"

7 0
3 years ago
Which of the following things would you access from the Program &amp; Courses page? Course descriptions Tutorial videos Account
Paraphin [41]

Course descriptions.

5 0
3 years ago
Other questions:
  • Laura has identified the job she wants, the skills needed for the position, and the areas she needs to improve in order to get i
    10·1 answer
  • Which type of attack modifies the fields that contain the different characteristics of the data that is being transmitted?
    7·1 answer
  • What are the features of a strong résumé? Check all that apply. The résumé is printed on regular printer paper. The résumé is we
    5·2 answers
  • private int product(int n) { if(n &lt;= 1) return 1; else return n * product(n-2); } What is the output when product(6) is calle
    6·1 answer
  • What are the characteristics of good blogs?
    8·1 answer
  • Controlling access of information on the internet
    15·1 answer
  • What is the difference between dsl and dial up?
    14·1 answer
  • In what situations might you need to use a function that calls another function?
    11·1 answer
  • How do i know my child's login info for parent infinite campus
    14·1 answer
  • Write l for law of enrtia,ll for law of Acceleration and lll for law of enteraction.
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!