Playing poker with dice. (Kinda like Yahtzee) . Have the user enter 5 dice rolls
ID: 3853936 • Letter: P
Question
Playing poker with dice. (Kinda like Yahtzee) . Have the user enter 5 dice rolls (1-6) in any order. If any are outside of the 1 to 6 inclusive range, just end the program. . Count and print the number of ones entered . Count and print the number of twos entered Count and print the number of threes entered Count and print the number of fours entered Count and print the number of fives entered Count and print the number of sixes entered . Tell if there are three or more dice the same . Tell if there are four or more dice the same Tell if there are five dice the same . Tell if there is a full house, 3 the same and 2 the same of a different number . Tell if there is a long straight... 12 345 or 2 3 456. So 5 3 4 2 6 contains a long straight. Tell if there is a small straight (1 2 3 4) or (2 3 4 5) or (3 45 6). So 3 2 4 1 1 contains a small straight . Yes, you can read ahead, but you don't need toExplanation / Answer
#include <iostream>
using namespace std;
//Tell if there are three or more dice the same.
bool threeOrMoreTheSame(int diceFaces[])
{
for(int i = 0; i < 6; i++) //Starting from the first value till the last value.
if(diceFaces[i] >= 3) //If some face has appeared more than or equal to thrice.
return true; //Return true.
return false; //Return false otherwise.
}
//Tell if there are four or more dice the same.
bool fourOrMoreTheSame(int diceFaces[])
{
for(int i = 0; i < 6; i++) //Starting from the first value till the last value.
if(diceFaces[i] >= 4) //If some face has appeared more than or equal to four times.
return true; //Return true.
return false; //Return false otherwise.
}
//Tell if there are five dice the same.
bool fiveTheSame(int diceFaces[])
{
for(int i = 0; i < 6; i++) //Starting from the first value till the last value.
if(diceFaces[i] == 5) //If some face has appeared five times.
return true; //Return true.
return false; //Return false otherwise.
}
//Tell if there is a full house, 3 the same and 2 the same of different number.
bool fullHouse(int diceFaces[])
{
for(int i = 0; i < 6; i++) //Starting from the first value till the last value.
{
if(diceFaces[i] == 2) //If some face appears twice.
{
for(int j = 0; j < 6; j++) //If also some face appears thrice.
if(diceFaces[j] == 3)
return true; //Return true.
}
}
return false; //Return false otherwise.
}
//Tell if there is a long straight, 1, 2, 3, 4, 5 or 2, 3, 4, 5, 6.
bool longStraight(int diceFaces[])
{
if(diceFaces[0] == 0) //If 1 didn't appeared...
{
for(int i = 1; i < 6; i++) //Starting from face 2, to 6.
if(diceFaces[i] == 0) //If some face didn't appeared
return false; //It's not a long straight.
return true; //If all faces appeared atleast once, it's a long straight.
}
else
{
for(int i = 0; i < 5; i++) //Starting from face 1, to 5.
if(diceFaces[i] == 0) //If some face didn't appeared
return false; //It's not a long straight.
return true; //If all faces appeared atleast once, it's a long straight.
}
return false; //In all other cases, its not a long straight.
}
//Tell if there is a small straight, 1, 2, 3, 4 or 2, 3, 4, 5, or 3, 4, 5, 6.
bool smallStraight(int diceFaces[])
{
if(diceFaces[0] == 0 && diceFaces[1] == 0) //If 1 and 2 didn't appeared...
{
for(int i = 2; i < 6; i++) //Starting from face 3, to 6.
if(diceFaces[i] == 0) //If some face didn't appeared
return false; //It's not a small straight.
return true; //If all faces appeared atleast once, it's a small straight.
}
else if(diceFaces[0] == 0) //If 1 didn't appeared...
{
for(int i = 1; i < 5; i++) //Starting from face 2, to 5.
if(diceFaces[i] == 0) //If some face didn't appeared
return false; //It's not a small straight.
return true; //If all faces appeared atleast once, it's a small straight.
}
else
{
for(int i = 0; i < 4; i++) //Starting from face 1, to 4.
if(diceFaces[i] == 0) //If some face didn't appeared
return false; //It's not a small straight.
return true; //If all faces appeared atleast once, it's a small straight.
}
return false; //In all other cases, its not a long straight.
}