Can someone help me make my code work? (Code and errors in post)


I'm trying to make this code do this:
I have 12 die, 6 green, 4 yelow, 2 red.
the Green have 3 fish, 2 hooks, and a boot.
yellow has 2 of each.
red has 3 boot, 2 hook, 1 fish.

Now I've been trying to make this code have several players. The first player grabs 3 dice from the cup, then rolls. Each fish counts as a point, and each boot counts as a strike, while each hook gets put back in the cup. Then do this as many times as there are people, and then end code.


Now the main errors I am getting are this:

"Turn" is unreferenced local variable
playerScore is unreferenced.
conversion from time_t to unsigned int, possible loss.
"turn" undeclared identifier



#include <cstdlib>
#include <ctime>
#include <iostream>
using namespace std;

void greenDice();
void yellowDice();
void redDice();
int fish();
int hook();
int boot();

int main()
{
int playerScore[4];
int turn[3];
int players;
int input;

cout << "Welcome to the Fish Die game!";
cout << "Press 1 for rules, or 2 to start the game.";
cin >> input;

if(input == 1) {
cout << "The rules are simple! Pick 3 dice out of the cup, then roll!\n";
cout << "Each fish you roll counts as 1 point,\n";
cout << "Each boot you roll counts as a strike, and any hooks can be rerolled. ";
cout << "Each roll set aside any fish and boots and reroll 3 die again.\n";
cout << "The first to 12 fish wins. If you get 3 boots, you get 0, and your turn is over.\n";
} else {
cout << "How many players will there be?\nEnter a number greater than 2\n";
}

while(players >= 2 && players <= 12) {
cin >> players;
cout << "Please enter a valid number";
}

system("PAUSE");
return 0;
}

void roll()
{
srand(time(0));
int s;

for (int x = 1; x < 4; x++)
s = rand()%13;

if (s < 6) {
greenDice();
} else if(s > 5 && s<9) {
yellowDice();
} else if(s>8) {
redDice();
}
}

void greenDice()
{
srand(time(0));
int g;

g = rand()%6;

if(g< 3) {
fish();
} else if(g>2 && g<5) {
hook();
} else if(g>4) {
boot();
}
}

void yellowDice()
{
srand(time(0));
int y;

y = rand()%6;

if(y<2) {
fish();
} else if(y>1 && y<4) {
hook();
} else if(y>3) {
boot();
}
}

void redDice()
{
srand (time(0));
int r;
r = rand()%6;

if (r<1) {
fish();
} else if(r>0 && r< 3) {
hook();
} else if(r>2) {
boot();
}
}

int fish()
{
cout << "You rolled a fish";
++turn[1];
}

int hook()
{
cout << "You rolled a hook";
++turn[2];
}

int boot()
{
cout <<"You rolled a boot.";
++turn[3];
}

You need to create an array with help of the players-variable, otherwise you have nowhere to store the value and the players value just takes the value of the input.

I'm also unsure of what the turn(?) array does? Is it supposed to keep track of turns for each player? Really hard to understand without any comments. Also, use the [.code] [./code] function to make the readability of your program better.


"Turn" is unreferenced local variable
playerScore is unreferenced.
conversion from time_t to unsigned int, possible loss.
"turn" undeclared identifier


Turn has no starting values.
playerScore is unused -- Initiate all of the values to 0, and create an array with the same amount as players, same with turn.
srand((unsigned) time(0)) -- To fix the possible loss problem by using typecasting.
srand is only needed in the top of main.
Last edited on
Yeah, the turn is supposed to keep track of each turn. And I also have this:

http://pastebin.com/yw2TZZKw

And what do you mean srand is only needed in the top?
Also will this do what I need it to do?
Topic archived. No new replies allowed.