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)
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
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
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.
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.