im making a hangman game but the problem i have right now is that i can't declair my string inside of my class :(
here is what im using inside of the public part of the class
string words[10] = { "program", "networking", "software", "torrent", "java", "ubuntu", "windows", "processor", "motherboard", "hardware"};
i could put it in main but i would like it to be in the class.
class MyClass
{
string mystr;
MyClass() //this is a constructor, it takes the name of the class, and it gets executed when the class's object instance is created
{
mystr = "whatever you want here";
}
};
int main(){
hangman object;
char playagain;
srand(time(NULL));
do{
system("CLS");
int a = rand() % 10 + 1;
cout << object.words[a]; //how do i use the words string now??
cout << "Do you want to play again? Y/N ";
cin >> playagain;
}while(playagain == 'Y' || playagain == 'y');
system("PAUSE");
return 0;
}
snig, my friend, you have to read more about classes. I can't give you a tutorial on how to use classes. The way you use it depends very much on what you wanna do. Please read the tutorial of this website about classes: