I'm coding a light version of a yahtzee game. What I want to do in the program is as followed: The game starts with rolling all the dice, after that you need to get as many ones to start with and then moving on to twos after you have tossed the dices 3 times. So basicly, first 3 tosses is about getting as many ones as possible. Next three tosses is about getting as many twos as possible, you do this up to sixes. after the first toss, you are given the answer to keep dices, I have chosen to do this in a FOR LOOP, that for each dice "i" you get the question, "Do you want to keep dice" the player answers with (y/n) and the dice that the player wants to keep will be put in an array, after the the last toss the array will be filled with the rest of the dices.
I'll give you an example,
first toss, the player gets: 1. 6. 4. 3. 1.
so the player decides to keep dice number 1 and 6.
so they will be put in the array.
I'll explain what I want to do in psudocode:
while(!tossedThreeTimes, not saved 5) {
toss all.
print out all - saved.
Ask wich dice to keep.
for each keep.
nrOfToss++;
if nrOfToss done(3)
{
Fill keep
}
}
This is my code so far:
#include <iostream>
#include <string>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int main()
{
const int nrOfDice = 5;
const int nrOfPlayer = 1;
const int protocol = 7;
int nrOfRolls = 0;
int keep = 0;
int diceLeft = nrOfDice - keep;
char ans;
int dice[nrOfDice];
int result[protocol];
string player[nrOfPlayer];
int reRoll[nrOfDice];
int diceKeep[nrOfDice];
srand(time(NULL));
cout << "Player please enter your name: ";
getline(cin, player[0]);
cout << "Hello " << player[0] << endl;
int i = 0;
dice[i] = 0;
while (nrOfRolls != 3) {
for (int i = 0; i < 5; i++)
{
dice[i] = (rand() % 6) + 1;
}
result[0] = 0;
cout << "---> ";
for (int i = 0; i < 5; i++)
{
cout << dice[i] << ". ";
}
/*cout << "Dice To Keep: ";
cin >> keep;*/
cout << endl;
for (int i = 0; i < nrOfDice; i++)
{
cout << "Do you want to keep die: " << i + 1 << endl;
cout << "(Y/N) - ";
cin >> ans;
if (ans == 'y' || 'Y')
{
dice[i] + i;
dice[i] = (rand() % 6) + 1;
}
}
nrOfRolls++;
if (nrOfRolls == 3)
{
cout << "Your Final Dice is: ";
for (int i = 0; i < 5; i++)
{
//dice[i] + diceLeft;
dice[i] + i;
cout << dice[i] << ". ";
}
/*dice[nrOfDice] + diceLeft;
cout << dice[nrOfDice];*/
}
}
system("pause");
getchar();
return 0;
}
As you can see, I havent really forfilled what i described in psudocode. The thing is that im totally stuck as this point and could really need som code help to get this program working, I know that I'm almost done I just need to get my code correct. The thing that doesn't work in program now is that i cant get the function where the user chooses which dice he/she wants to keep in an array and after that print out the final dice after three tosses. My code is what I have came up with so far, and I dont know what to change in it.
Hope you have understood what I've explained and if you didn't, just let me know and I will try to explain it "better"
Thanks.

New Topic/Question
Reply


MultiQuote



|