In: Computer Science
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++
#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