Write a program that simulates a throw of two 900-sided dice and indicates whether or not the sum of the results is divisible by three?
Required code in C++ -->
#include <iostream>
#include <random>
int main()
{
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<> distr(1, 900);
int x=distr(gen); // a random value will be stored in x
std::cout<<"we get"<<x<<"\n"; // x will be
displayed
int y=distr(gen); // a random value will be stored in y
std::cout<<"we get"<<y<<"\n"; // y will be
displayed
int sum=x+y; // addition of x,y will be stored in sum
if(sum%3==0){ // if sum is divisible by 3
std::cout<<"Divisible by 3"; // output - divisible by 3
}
else{
std::cout<<"Not Divisible by 3"; //else not divisible
}
}
Get Answers For Free
Most questions answered within 1 hours.