Skip to content

Instantly share code, notes, and snippets.

@johnhamelink
Created June 25, 2012 23:22
Show Gist options
  • Save johnhamelink/2992067 to your computer and use it in GitHub Desktop.
Save johnhamelink/2992067 to your computer and use it in GitHub Desktop.
#ifndef HAND_H
#define HAND_H
// For IO
#include <iostream>
#include <string>
// For random
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
class hand
{
public:
hand();
~hand(){};
string getType() { return type[0]; };
protected:
string type[3];
int random;
};
hand::hand()
{
string types[3][3] = {
{ "rock", "paper", "scissors" },
{ "paper", "scissors", "rock" },
{ "scissors", "paper", "rock" }
};
// Initialise with a random seed
srand ( time(NULL) );
// Random number from 0 to 2
random = rand() % 3;
type = types[random];
}
#endif
#include <string>;
#include <iostream>;
using namespace std;
#include "hand.h";
#include "player.h";
int main(int argc, const char *argv[])
{
hand h;
cout<<h.getType()<<endl;
return 0;
}
@johnhamelink
Copy link
Author

When I compile with G++ I get the following:

john at Johns-iMac in ~/Sites/c++/rockPaperScissors 
$ g++ main.cpp -o rockPaperScissors
In file included from main.cpp:6:
hand.h: In constructor ‘hand::hand()’:
hand.h:38: error: invalid array assignment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment