3 dice game

guys can any1 help me out w i dnw evn with this question please i dnw evn wer to start:(

=============================================================================


You task is to write a C++ program for a new kind of dice game. In this game, only 3 (three) dice are
used. You need to write a function to throw one dice (using pseudo random numbers), as well as a
function which returns the result of three dice values (separately). You must send these three dice
rolls by VALUE to a scoring function, which determines the score based on the following criteria:

f(d1,d2,d3)=(d1*10+d2*5)/(d3*6)


You must allow any number of people to play a user specified number of rounds. (I.E. Ask the user
how many people and also ask how many rounds). Also make an option available that the rounds do
not stop until the maximum score is reached (you must work out the maximum score possible).
Make sure you allow the users to see their throws each time. (Use cin.get() to read the enter key)
where is the problem?
do you know how to use rand()?
You should attempt what you can and post it. This helps you learn better. For example, can you write the function that will take three dice values (d1, d2, d3) and return the score based on the formula you've been given?

I'm not sure if you have learnt about classes yet, but I think 'Dice' would be a good candidate class. It could have a 'roll' method and a property 'faceValue'. You could then use three instances of the Dice class to represent your three dice.

Focus on getting the basics in first, then worry about what's described in the second paragraph of your brief. Hope that helps.
Can ayone plz help me with this code im trying to understand how user defined functions works, the program compiles bt im suposed to use a function to generate 4 random numbers and i dont knw how

#include <iostream>
#include <time.h>
#include <cstdlib>


using namespace std;

//Declare Functions used

void one();
void two();
void three();
void four();
void five();
void six();
int arrange(int&in1,int&in2,int&in3,int&in4);




int main()

{ //Declare Variables

int num;
int num2;
int num3;
int num4;
char Dice_Roll;
//Initialize random number generator

srand(time(NULL));

cout << "*******************************" << endl;
cout << "*----Welcome to BEAT THAT-----*" << endl;
cout << "*******************************" << endl<<endl;

while (Dice_Roll != 'e')
{ int in1;
int in2;
int in3;
int in4;
cout <<"Type r to Roll dices or e to Exit the Game: ";
cin >> Dice_Roll;
num = 1 + rand() % (6 );
num2 = 1 + rand() % (6);
num3 = 1 + rand() % (6);
num4 = 1 + rand() % (6);
cout << endl;
in1=num;
in2=num2;
in3=num3;
in4=num4;

if (Dice_Roll == 'e')
break;
if (Dice_Roll != 'r')
{
continue;
}

switch (num)
{
case 1:
one();
break;
case 2:
two();
break;
case 3:
three();
break;
case 4:
four();
break;
case 5:
five();
break;
case 6:
six();
break;
} //end switch

switch (num2)
{
case 1:
one();
break;
case 2:
two();
break;
case 3:
three();
break;
case 4:
four();
break;
case 5:
five();
break;
case 6:
six();
break;
} //end switch

switch (num3)
{
case 1:
one();
break;
case 2:
two();
break;
case 3:
three();
break;
case 4:
four();
break;
case 5:
five();
break;
case 6:
six();
break;
} //end switch

switch (num4)
{
case 1:
one();
break;
case 2:
two();
break;
case 3:
three();
break;
case 4:
four();
break;
case 5:
five();
break;
case 6:
six();
break;
cout<<endl;
cout<<endl;
} //end switch
arrange(in1,in2,in3,in4);
{
cout << endl << "You Rolled: " << num << ", " << num2 << ", " << num3 << ", " << num4 <<endl;
cout << endl << "Arranged: " << in1 << ", " << in2 << ", " << in3 << ", " << in4 <<endl;
cout<<endl;
}
}

return 0;
}

// Function definition.
void one()
{
cout << " -----" << endl;
cout << "| |" << endl;
cout << "| * |" << endl;
cout << "| |" << endl;
cout << " -----" << endl;
}
void two()
{
cout << " -----" << endl;
cout << "| *|" << endl;
cout << "| |" << endl;
cout << "|* |" << endl;
cout << " -----" << endl;
}
void three()
{
cout << " -----" << endl;
cout << "| *|" << endl;
cout << "| * |" << endl;
cout << "|* |" << endl;
cout << " -----" << endl;
}
void four()
{
cout << " -----" << endl;
cout << "|* *|" << endl;
cout << "| |" << endl;
cout << "|* *|" << endl;
cout << " -----" << endl;
}
void five()
{
cout << " -----" << endl;
cout << "|* *|" << endl;
cout << "| * |" << endl;
cout << "|* *|" << endl;
cout << " -----" << endl;
}
void six()
{
cout << " -----" << endl;
cout << "|* *|" << endl;
cout << "|* *|" << endl;
cout << "|* *|" << endl;
cout << " -----" << endl;
}


int arrange(int& in1,int& in2,int& in3,int& in4)
{
int temp;
if(in1<in2)
{
temp = in1;
in1 = in2 ;
in2 = temp;
}
if(in1<in3)
{
temp = in1;
in1 = in3;
in3 = temp;
}
if(in1<in4)
{
temp = in1;
in1 = in4;
in4 = temp;
}
if(in2<in3)
{
temp = in2;
in2 = in3;
in3 = temp;
}
if(in2<in4)
{
temp = in2;
in2 = in4;
in4 = temp;
}
if(in3<in4)
{
temp = in3;
in3 = in4;
in4 = temp;
}

}



Last edited on
Firstly, you shouldn't be doing a check on 'Dice_Roll' before you initialise it. It should be a do-while loop.

The code is a bit bloated. You need to think about how you can make it more concise. We're here to help, but you need to ask specific questions. I'm guessing that you're not doing the same problem as blaze745.

Once I made it a do-while loop, it seemed to work ok (it outputted results 1, 6, 4 and 5, and then arranged them). If you want more information, ask a specific question.
I need help with creating a function that will call four dices instead of repeating,

num = 1 + rand() % (6);
num2 = 1 + rand() % (6);
num3 = 1 + rand() % (6);
num4 = 1 + rand() % (6);

The question was write a C++ version of the game called BEAT THAT! In this game, a player will roll four dice and the program must generate a random number between 1 and 6 for four different dice. Then the program must sort these four numbers in such a manner that the largest possible number is formed.This must happen until the user wishes to stop (you must ask the user if they wish to continue).
Check if the new number is greater than the previous number. For example:
* * * * * *
* * * *
* * * * * *
5 2 6 3 rearranged to make the highest number is 6532.
Your program must have at least two functions. One function called DICE_ROLL which generates and
returns a random number between one and six, and another called ARRANGE which takes four
parameters and returns the largest possible number.
For bonus marks – output the dice rolls in the ‘star style’ shown above every time the dice is rolled.
Each roll may be on a new line.
Last edited on
instead of repeating,

num = 1 + rand() % (6);
num2 = 1 + rand() % (6);
num3 = 1 + rand() % (6);
num4 = 1 + rand() % (6);

you can use the for loop

for (i = 0; i < 4; i++)
num[i] = 1 + rand() % (6);
Topic archived. No new replies allowed.