Question

In: Computer Science

Q:You have to write a function that contains three varibles as the following Diamond Gold Silver...

Q:You have to write a function that contains three varibles as the following

Diamond
Gold
Silver

Each varible has a one third (1/3) chance of appearing with a random quantity between (1 & 2)

as a visual basic / C++

Solutions

Expert Solution

#include <iostream>

#include <cstdlib> // for using rand func

#include <ctime> // for using time

using namespace std;

int main() {

srand(time(NULL)); // setting up so that it pop ups random numbers

int Diamond=-1; // intializng it with -1

int Gold=-1;// intializng it with -1

int Silver=-1;// intializng it with -1

int i=0; // just to keep count

int j=0; // for getting turns of all 3

while(i!=10){ // 10 times loop

j=(rand()%100)%3+1; // get index random

if(j==1){ // if it is 1

Diamond=(rand()%2)+1; // store random value betweem 1 and 2

cout<<"Random Value for Diamond: "<<Diamond<<endl;

}

if(j==2){

Gold=(rand()%2)+1; // store random value betweem 1 and 2

cout<<"Random Value for Gold: "<<Gold<<endl;

}

if(j==3){

Silver=(rand()%2)+1;// store random value betweem 1 and 2

cout<<"Random Value for Silver: "<<Silver<<endl;

}

i++;

}

}

OUTPUT:

IF YOU HAVE ANY QUERY PLEASE COMMENT DOWN BELOW

PLEASE GIVE A THUMBS UP


Related Solutions

Three hats each contain ten coins. Hat 1 contains two gold coins, five silver coins and...
Three hats each contain ten coins. Hat 1 contains two gold coins, five silver coins and three copper coins. Hat 2 contains four gold coins and six silver coins. Hat 3 contains three gold coins and seven copper coins. We randomly select one coin from each hat. (a) The outcome of interest is the colour of each of the three selected coins. List the complete sample space of outcomes and calculate the probability of each. (b) Let X be the...
Three hats each contain ten coins. Hat 1 contains two gold coins, five silver coins and...
Three hats each contain ten coins. Hat 1 contains two gold coins, five silver coins and three copper coins. Hat 2 contains four gold coins and six silver coins. Hat 3 contains three gold coins and seven copper coins. We randomly select one coin from each hat. (a) The outcome of interest is the color of each of the three selected coins. List the complete sample space of outcomes and calculate the probability of each. (b) Let X be the...
a give the probability of getting a sequence of Gold then Silver then Blue on three...
a give the probability of getting a sequence of Gold then Silver then Blue on three consecutive spins. b.If the wheel is spun four times, give the probability of getting Blue only on the fourth spin. c.Give the probability of getting at least one Blue on five consecutive spins. there are 4 red spaces, 2 blue, one gold, and one silver space.
Write a program that contains a function that takes in three arguments and then calculates the...
Write a program that contains a function that takes in three arguments and then calculates the cost of an order. The output can be either returned to the program or as a side effect. 1. Ask the user via prompt for the products name, price, and quantity that you want to order. 2. Send these values into the function. 3. Check the input to make sure the user entered all of the values. If they did not, or they used...
Fast $, Inc produces silver and gold pendants. The data are as follows: Silver                             
Fast $, Inc produces silver and gold pendants. The data are as follows: Silver                              Gold Price $30 $125 Material    8     35 Labor    5    73 Contribution Margin Labor Hours Required $0 .75 $1.00 Demand 100 75 Fixed Costs = $10,000; Labor hours available = 100 Are there enough labor hours to satisfy demand for both types?_____ Determine the contribution margin per labor hours for each How many silver pendants and how many gold pendants would maximize profits?...
There are three light fixtures. 70 bronze; 120 gold; & 35 silver.    The common costs for...
There are three light fixtures. 70 bronze; 120 gold; & 35 silver.    The common costs for those 225 fixtures was $38,650. Here are some more numbers that production gave me. Gold glass is $2.25 per panel. Bracket is $4.25. Bronze glass is $.75 per panel. Bracket is $3.25.   Silver glass is $1.75 per panel and bracket is $2.73. Given the processing sequence, is there a split off point or points? What does that mean? If there is a split off...
**Question 4**: Three identical-looking chests contain the following booty: 1) 40 gold coins, 20 silver, and...
**Question 4**: Three identical-looking chests contain the following booty: 1) 40 gold coins, 20 silver, and 40 bronze 2) 20 gold coins, 70 silver, and 10 bronze 3) 10 gold coins, 20 silver, and 70 bronze Each chest is locked, but all have a small slit at the top where you could deposit additional coins (and maybe shake out a coin already inside). You select one of the chests at random, pick it up, and shake it. Out of the...
In C++, 
 Define a structure Triangle that contains three Point members. Write a function that computes...
In C++, 
 Define a structure Triangle that contains three Point members. Write a function that computes the perimeter() of a Triangle. Write a program that reads the coordinates of the points, calls your function, and displays the result. C++
A consumer has 10 pounds of gold and 20 pounds of silver. The price of gold...
A consumer has 10 pounds of gold and 20 pounds of silver. The price of gold ?) = $4,000 a pound while the price of silver ?* = $1,000 a pound. Gold and silver are the only two goods that can be consumed. Write down the budget constraint of this consumer and draw it on a graph. Suppose that the price of silver increases to $2,000 a pound. Draw the new budget constraint. Has the purchasing power of our consumer...
Write a program that contains the following Write a function copies with two int parameters, named...
Write a program that contains the following Write a function copies with two int parameters, named n and x. It should dynamically allocate a new array of size n.  The function should then copy the value in x to every position in the array. The function should return a pointer to the new array. In the main function, call the copies function from part 1. with size 5 and value -1.  Output the resulting array to the screen, and deallocate the array....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT