Here are the errors I get:
Code:
--------------------Configuration: Hangman - Win32 Debug--------------------
Compiling...
Main.cpp
Linking...
Main.obj : error LNK2005: "struct hangman hang" (?hang@@3Uhangman@@A) already defined in Hangman.obj
Debug/Hangman.exe : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.
Hangman.exe - 2 error(s), 0 warning(s)
Here's all my code... (again...)
Code:
//Main.h: Main .cpp file
#include <iostream>
#include <windows.h>
#include <string.h>
#include "Hangman.h"
int main()
{
cout<<"|-| /-\\ |\\| G |\\/| /-\\ |\\|"<<endl;
hang.LoopProgram();
return 0;
}
Code:
//Hangman.cpp: Constructors, function definitions, etc for Hangman.h
#include <iostream.h>
#include <string.h>
#include <windows.h>
#include "Hangman.h"
//Hangman Constructor
hangman::hangman()
{
hang.loopvar=true;
hang.PickWord();
hang.length=strlen(hang.word);
hang.spaces = new char[ hang.length ];
for(short x=0; x<hang.length; x++)
{
spaces[x]='_';
}
}
//Hangman Destructor
hangman::~hangman()
{
delete[] spaces;
}
//Function that loops the program until told to stop
void hangman::LoopProgram()
{
while(hang.loopvar!=false)
{
hang.BlankSpaces();
hang.Guess();
hang.Check();
}
}
//Function that picks a random word
void hangman::PickWord()
{
srand(GetTickCount());
short random=rand()%15;
switch(random)
{
case 0:
strcpy(hang.word, "corndog");
break;
case 1:
strcpy(hang.word, "computer");
break;
case 2:
strcpy(hang.word, "telephone");
break;
case 3:
strcpy(hang.word, "electric");
break;
case 4:
strcpy(hang.word, "stereo");
break;
case 5:
strcpy(hang.word, "oreo");
break;
case 6:
strcpy(hang.word, "microphone");
break;
case 7:
strcpy(hang.word, "cat");
break;
case 8:
strcpy(hang.word, "moose");
break;
case 9:
strcpy(hang.word, "internet");
break;
case 10:
strcpy(hang.word, "cow");
break;
case 11:
strcpy(hang.word, "potato");
break;
case 12:
strcpy(hang.word, "card");
break;
case 13:
strcpy(hang.word, "oven");
break;
case 14:
strcpy(hang.word, "speakers");
break;
default:
strcpy(hang.word, "earthquake");
}
}
//Function that draws all of the spaces
void hangman::BlankSpaces()
{
for(short x=0; x<hang.length; x++)
{
system("cls");
cout<<spaces[x]<<" ";
}
}
//Function that gets the user's guess
void hangman::Guess()
{
cout<<endl<<"What's your guess?: ";
cin>>hang.letter;
}
//Function that checks to see if the letter is in the word, if the word is complete, or the... man is hanged
//or however you want to put it. Also adds another number to the NumGuesses variable.
void hangman::Check()
{
//Check to see if letter guess is in word
for(short x=0;x<hang.length;x++)
{
if(hang.word[x]==hang.letter)
{
hang.spaces[x]=hang.letter;
}
}
//Check to see if the word is complete
if(strcmp(hang.spaces,hang.word)==0)
{
MessageBox(NULL, "You Won!", hang.word, MB_OK);
hang.loopvar=false;
}
}
Code:
//and lastly...
//Hangman.h: Struct definition
#include <string>
using namespace std;
struct hangman
{
bool loopvar;
char word[10];
int length;
char letter;
char* spaces;
hangman();
~hangman();
void LoopProgram();
void PickWord();
void BlankSpaces();
void Guess();
void Check();
}hang;
Hopefully this should be it for my hangman program. But like some people say even though most of the time it's not true... "Ask and you shall recieve...". Hey, that sounds good, maybe that should be my quote... nah....