Question

In: Computer Science

create two random numbers between 1 and 6. if when the sum of two numbers are...

create two random numbers between 1 and 6. if when the sum of two numbers are added togethere their sum is less than 5 or greater than 12, output to the console: "you win". if is not, output "you lose"

C++

Solutions

Expert Solution

Answer-

Your code is here-

  • #include<iostream>
  • #include<cstdlib>
  • using namespace std;
  • main() {
  • int max;
  • int a,b;
  • int sum=0;
  • max = 6; //set the upper bound to generate the random number
  • srand(time(0));
  • a=rand()%max +1; //genrate the number 1 to 6
  • b=rand()%max +1;
  • cout << "The random number is: "<<a; //display first genrate number
  • cout<<"\n";
  • cout << "The random number is: "<<b; ////display second genrate number
  • sum=a+b;
  • cout<<"\n"<< "sum="<<sum; //display sum
  • if(sum<5 || 12<sum) //condition sum is less than 5 or greater than 12
  • {
  • cout<<"\n"<<"you win";
  • }
  • else
  • {
  • cout<<"\n"<<"you lose";
  • }   
  • }

screenshot of running program and output-

Note- Please do upvote, if any problem then comment in box sure I will help.


Related Solutions

Sum of numbers between 1 and 10
Calculate the values from the  smallest number to the largest number
****java*** Create an application that generates 20 random numbers between 1 and 100 and writes them...
****java*** Create an application that generates 20 random numbers between 1 and 100 and writes them to a text file on separate lines. Then the program should read the numbers from the file, calculate the average of the numbers, and display this to the screen.
Q2: The following code is supposed to return the sum of the numbers between 1 and...
Q2: The following code is supposed to return the sum of the numbers between 1 and n inclusive, for positive n. An analysis of the code using our "Three Question" approach reveals that: int sum(int n){ if (n == 1)     return 1; else     return (n + sum(n - 1)); } Answer Choices: it passes on all three questions and is a valid algorithm.     it fails the smaller-caller question.     it fails the base-case question.     it fails...
The sum of two numbers is 35 and their difference is 13. Find the numbers?
The sum  of two numbers is 35 and their difference is 13. Find the numbers?
Suppose you roll two 6 sided dice, letting X be the sum of the numbers shown...
Suppose you roll two 6 sided dice, letting X be the sum of the numbers shown on the dice and Y be the number of dice that show an odd number. a) Find the joint pmf of <X,Y> b) Find the marginals pmf's for both variables. c) Are X and Y independent?
Suppose you roll two 6 sided dice, letting X be the sum of the numbers shown...
Suppose you roll two 6 sided dice, letting X be the sum of the numbers shown on the dice and Y be the number of dice that show an odd number. a) Find the joint pmf of <X,Y> b) Find the marginals pmf's for both variables. c) Are X and Y independent?
Suppose you roll two 6-sided dice, letting X be the sum of the numbers shown on...
Suppose you roll two 6-sided dice, letting X be the sum of the numbers shown on the dice and Y be the number of dice that show an odd number. a) Find the joint pmf of <X,Y> b) Find the maringals pmf's for both variables. c) Are X and Y independent?
Write a program in C++ that computes the sum of odd numbers between 1 and 117....
Write a program in C++ that computes the sum of odd numbers between 1 and 117. Execute the program and submit a screen capture of the program and its results.
The sum of two numbers is 34. a)Find the largest possible product of these numbers.
  1-The sum of two numbers is 34.    a)Find the largest possible product of these numbers.    b)What would be the largest possible product if the sum if the two numbers were "k"? 2-Sixty meters of fencing are used to fence a rectangular garden.    a)Find the dimensions that will give that maximum area.    b)What would be the maximum area if "k" feet of fencing were used in terms of "k"? THANK YOU
A die is thrown twice and the sum of the numbers rising is noted to be 6.
  A die is thrown twice and the sum of the numbers rising is noted to be 6. Calculate the is the conditional probability that the number 4 has arrived at least once?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT