67 107
Assignments Done
99,3%
Successfully Done
In November 2018

# Answer to Question #57613 in C++ for William

Question #57613
Write code that simulates the roll of two dice. If the two dice have the same value, output the statement "Doubles. Roll again." Otherwise, print "Your turn is over.";
// This program simulates the roll of two dice. If the two dice have the same value,
// output the statement "Doubles. Roll again." Otherwise, print "Your turn is over.";

// input: command "roll" or "quit")

#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>

int main()
{
int dice1;
int dice2;
std::string command;

srand ( time(NULL) );

do
{
std::cout << "Enter your command (\"quit\" or \"roll\"): ";
std::cin >> command;
if (command == "roll" )
{
dice1 = rand() % 6 + 1;
dice2 = rand() % 6 + 1;
std::cout << " dice1 = " << dice1 << std::endl;
std::cout << " dice2 = " << dice2 << std::endl;
if ( dice1 != dice2 )
{
std::cout << "Your turn is over." << std::endl;
}
else
{
std::cout << "Doubles. Roll again." << std::endl;
}
}
else if (command == "quit" )
{
return 0;
}
else
{
std::cout << "You have entered wrong command. " << std::endl;
}

}while(true);

return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!