Hey all! I have a couple problems regarding this Yahtzee program I am making for class. But I cant seem to fix the issues. It Should out put like this
Turn #1
Your first roll is: 1 1 5 4 1. (Type 'y' to re-roll or 'n' to stay)
n n y y n
Your second roll is: 1 1 3 2 1. (Type 'y' to re-roll or 'n' to stay)
n n y y n
Your third roll is: 1 1 1 2 1
Under what category would you like to record your score:
1 - Ones, 2 - Twos, 3 - Threes,
4 - Fours, 5 - Fives, 6 - Sixes,
7 - Three of a Kind, 8 - Four of a Kind, 9 - Full House,
10 - Small Straight, 11 - Large Straight, 12 - Yahtzee,
13 - Chance, 14 - Scratch
7 - Three of Kind 0 8 - Four of Kind 0 9 - Full House 0
10 - Sm. Straight 0 11 - Lg. Straight 0 12 - Yahtzee 0
13 - Chance 0
Where the "n" and "y" parts are the users input.
My code for this is
#include <iostream>
#include <time.h>
using namespace std;
void rollDies(int dice[], char choise[]);
void display(int dice[]);
void display(int category, int value);
void readChoise(char choise[]);
int main()
{
srand(time(NULL));
int dice[5];
int categories[14] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int category;
int bonus = 0;
char ch = 'y';
do{
char choise[5] = {'y','y','y','y','y'};
rollDies(dice,choise);
cout<<"your first roll is: ";
display(dice);
cout<<". (Type 'y' to re-roll or 'n' to stay)"<<endl;
readChoise(choise);
rollDies(dice,choise);
cout<<"your second roll is: ";
display(dice);
cout<<". (Type 'y' to re-roll or 'n' to stay)"<<endl;
readChoise(choise);
rollDies(dice,choise);
cout<<"your third roll is: ";
display(dice);
cout<<"\n\nUnder what category would you like to record your score: ";
cout<<"\n1 - Ones, 2 - Twos, 3 - Threes,";
cout<<"\n4 - Fours, 5 - Fives, 6 - Sixes,";
cout<<"\n7 - Three of a Kind, 8 - Four of a Kind, 9 - Full House,";
cout<<"\n10 - Small Straight, 11 - Large Straight, 12 - Yahtzee,";
cout<<"\n13 - Chance, 14 - Scratch"<<endl;
cout<<"\n\nChoice (1-14): ";
cin>>category;
categories[category-1] = categories[category-1] +1;
for(int i=0;i<14;i++)
display(i,categories[i]);
int score_1_6 = 0;
for(int i=0;i<6;i++)
score_1_6 += categories[i];
if(score_1_6 >= 63)
bonus = 50;
int Yahtzee = categories[11] ;
if(Yahtzee > 0)
bonus += 50 + (Yahtzee - 1)*100;
cout<<"Bonus: "<<bonus<<endl;
cout<<"Do you want to play again: y or n : ";
cin>>ch;
}while(ch != 'n' && ch!= 'N');
return 0;
}
void rollDies(int dice[], char choise[])
{
for(int i=0;i<5;i++)
if(choise[i] == 'y')
dice[i] = (rand() % 6) +1;
}
void display(int dice[])
{
for(int i=0;i<5;i++)
cout<<dice[i]<<" ";
}
void display(int category, int value)
{
cout<<category<<" - ";
switch(category + 1)
{
case 1: cout<<"Ones"; break;
case 2: cout<<"Twos"; break;
case 3: cout<<"Threes"; break;
case 4: cout<<"Fours"; break;
case 5: cout<<"Fives"; break;
case 6: cout<<"Sixes"; break;
case 7: cout<<"Three of kind"; break;
case 8: cout<<"Four of Kind"; break;
case 9: cout<<"Full House"; break;
case 10: cout<<"Sm. Straight"; break;
case 11: cout<<"Lg. Straight"; break;
case 12: cout<<"Yahtzee"; break;
case 13: cout<<"Chance"; break;
case 14: cout<<"Scratch"; break;
}
cout<<" "<<value<<endl;
}
void readChoise(char choise[])
{
for(int i=0;i<5;i++)
cin>>choise[i];
}
The compilation problems I'm recieving are
In function 'int main()':
'srand' was not declared in the scope in line 11 and 17
In function 'void roolDies(int*, char*)'):
'rand' was not declared in this scope in line 61 and 17