Skip to content

Instantly share code, notes, and snippets.

Created December 9, 2013 02:53
Show Gist options
  • Save anonymous/ea835a51eb4dbe21bd37 to your computer and use it in GitHub Desktop.
Save anonymous/ea835a51eb4dbe21bd37 to your computer and use it in GitHub Desktop.
#include<stdlib.h>
#include <iostream>
#include <ctime>
using namespace std;
bool CardAlreadyPicked(int[],int,int);
void GenerateCards(int[],int);
void DisplayInstructions();
int getguess(int);
bool checkIfCorrect(int, int[], int[]);
const int FIVE = 5;
int main()
{
srand(time(NULL));
int compcards[FIVE]={0};
int playerguess[FIVE]={0};
int userinput, score = 0, numguessed = 0;
DisplayInstructions();
GenerateCards(compcards, FIVE);
cout<<"GenerateCards picked the following: ";
for (int i=0; i < FIVE; i++)
{
cout<<compcards[i]<<" ";
}
cout<< endl;
for(int i = 0; i<5; i++)
{
userinput = getguess(numguessed); // w/e gets returned gets stored in userinput
playerguess[i] = userinput; //strores whatever is in userinput to playerguess
cout<<"The number you inputed was: " <<userinput<<endl; //couts userinput
cout<<" " << endl;
checkIfCorrect(userinput, compcards, playerguess); //paases the userinput or card to check, compcards or the number gener'd, and the player guess
cout << score << endl;
}
}
bool checkIfCorrect(int checkcard, int compcards[], int player[]){
for (int i=0; i<5; i++)
{
if(compcards[i] == checkcard)
cout<<"correct"<< endl;
return true;
}
return false;
}
void GenerateCards(int cards[], int numCards){
for (int i=0;i<numCards;i++){ ///loops numcards times{5}
int randCard = rand() % 24 + 1; //assigns rand number 1-24 to randCard, bool function loop first time =0
while(CardAlreadyPicked(cards, i, randCard)){ //if finds two same nums evuates to true, get another num, then checks agian until false.
randCard = rand() % 24 +1;
}
cards[i] = randCard; //storeing unique card values
}
}
bool CardAlreadyPicked(int cards[], int numCards, int cardToCheck)
{
for (int i=0; i<numCards; i++)
{
if (cards[i] == cardToCheck) //keeps looping with while loop until false
{
return true;
}
}
return false;
}
int getguess(int num){
string cardstrings[24] = {"fierce tiger", "funny tiger", "silly tiger", "clever tiger", "fierce rabbit",
"funny rabbit", "sily rabbit", "clever rabbit", "fierce monkey", "funny monkey", "silly monkey", "clever monkey",
"fierce rooster", "funny rooster", "silly rooster", "clever rooster", "fierce horse", "funny horse",
"silly horse", "clever horse", "fierce ram", "funny ram", "silly ram", "clever ram"};
string userinput;
cout<<"Guess a card"<<endl;
getline(cin,userinput);
if(userinput == "fierce tiger"){
num = 1;}
else if(userinput == "funny tiger"){
num = 2;}
else if(userinput == "silly tiger"){
num =3; }
else if(userinput == "clever tiger"){
num =4; }
else if(userinput == "fierce rabbit"){
num =5; }
else if(userinput == "funny rabbit"){
num =6; }
else if(userinput == "silly rabbit"){
num =7; }
else if(userinput == "clever rabbit"){
num =8; }
else if(userinput == "fierce monkey"){
num =9; }
else if(userinput == "funny monkey"){
num =10; }
else if(userinput == "silly monkey"){
num =11; }
else if(userinput == "clever monkey"){
num =12; }
else if(userinput == "fierce rooster"){
num =13; }
else if(userinput == "funny rooster"){
num =14; }
else if(userinput == "silly rooster"){
num =15; }
else if(userinput == "clever rooster"){
num =16; }
else if(userinput == "fierce horse"){
num =17; }
else if(userinput == "funny horse"){
num =18; }
else if(userinput == "silly horse"){
num =19; }
else if(userinput == "clever horse"){
num =20; }
else if(userinput == "fierce ram"){
num =21; }
else if(userinput == "funny ram"){
num =22; }
else if(userinput == "silly ram"){
num =23; }
else if(userinput == "clever ram"){
num =24; }
return num;
}
void DisplayInstructions(){
cout<<"instructions here"<<endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment