Hey guys,
Im a beginner in c++ programming, and i desperatly need some help here.
We were given a holiday project in class where we can come up with anything we want as long as its creative. So my friend and I got a wicked idea and we implemented on it. We thought we would make a c++ program which can be used to gamble on simple games. Yeah i know its nothing great, but keep in mind we're still beginners. Lol. Anyways everything was going fine till we decided to introduce hangman into it. And then things just went down. The source code for our project is given below. When we compile it, it shows as make failed and these are the errors:
Multiple decleration for 'boolean'
Earlier decleration of 'boolean'
Extra parameter in call to playGame()
This is my source code:
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
#include<process.h>
#include<math.h>
#include<ctype.h>
#include<string.h>
#include<windows.h>
#include<iomanip.h>
static void playGame();
static void printMistakes(int n);
static int const MAXGUESS=8;
static int const MAXLETTER='z'-'a'+1;
static char String[][15]={"table", "chair", "hipphopopotamus", "guitar", "extreme", "nostalgia", "pizza", "horse", "monkey", "cheese", "television", "radio", "equation", "computer", "astrology"} ;
enum boolean
{
False,
True
};
long int hangman(long int amt)
{
int bet, r=0;
boolean again;
char answer;
cout<<"\n""\n""\t"<<"This is a word guessing game called HANGMAN.";
cout<<"\n""\t"<<"The computer will pick a word"<<"\n""\t"<<"You must try to guess the letters in the word"<<"\n""\t"<<"If you guess the word with less than "<<MAXGUESS<<" mistakes, then you win!";
cout<<"\n""\n"<<"Win ensures double payback of bet money."<<"\n"<<"Loss results in complete loss of bet money."<<"\n""\n"<<"Place your bet money: ";
cin>>bet;
amt-=bet;
do
{
playGame(r);
if(r==1)
amt+=(bet*2);
else
amt+=0;
cout<<"\n""\n"<<"Would you like to play another game? (y/n)";
cin>>answer;
if(answer=='y'||answer=='Y')
again=true;
else if(answer=='n'||answer=='N')
return amt;
else
{
again=false;
cout<<"\n"<<"Your answer should be y or n.";
}
}while(again);
}
int playGame(int p)
{
boolean*already;
char c;
boolean*display;
int found;
int i;
char inputChar;
char inputString[15];
int length;
int letters;
int mistakes,score,chanscor;
boolean playing;
char word[15];
mistakes=0;
score=0;
randomize();
strcpy(word,String[(int)(rand()%26)]);
length=strlen(word);
display=new boolean[length];
letters=0;
for(i=0;i<length;i++)
{
c=word[i];
if((c>='a')&&(c<='z'))
{
display[i]=false;
letters++;
}
else
display[i]=true;
}
cout<<"\n""\n"<<"I am thinking of a word.";
if(letters==1)
cout<<"The word has one letter.";
else
cout<<"The word has "<<letters<<" letters.";
already=new boolean[MAXLETTER];
for(i=0;i<MAXLETTER;i++)
already[i]=false;
playing=true;
while(playing)
{
chanscor=100/(MAXGUESS-mistakes);
cout<<"\n"<<"The word is: ";
for(i=0;i<length;i++)
{
cout<<" ";
if(display[i])
cout<<word[i];
else
cout<<"*";
}
cout<<"\n"<<"What is your guess? ";
if((MAXGUESS-mistakes)<=1)
cout<<"This is your last guess! ";
else
cout<<"You have "<<(MAXGUESS-mistakes)<<" guesses remaining.";
gets(inputString);
strlwr(inputString);
if(strlen(inputString)==length)
{
if(strcmp(word,inputString)==0)
{
cout<<"Yes, the word is \""<<word<<"\"!";
printMistakes(mistakes);
p=1;
return p;
playing=false;
}
else
{
cout<<"Sorry the word is not \""<<inputString<<"\".";
mistakes++;
}
}
else if(strlen(inputString)!=1)
{
cout<<"Your guess \""<<inputString<<"\" must be one letter or the entire word.";
}
else
{
inputChar=inputString[0];
if((inputChar<'a')||(inputChar>'z'))
{
cout<<"Your guess \""<<inputChar<<"\" must be a letter from A to Z or the entire word";
}
else if(already[inputChar-'a'])
{
cout<<"You have already guessed the following letters: ";
for(i=0;i<MAXLETTER;i++)
if(already[i])
cout<<" "<<(char)(i+'a');
cout<<"\n";
}
else
{
already[inputChar-'a']=true;
found=0;
for(i=0;i<length;i++)
if(word[i]==inputChar)
{
display[i]=true;
found++;
}
if(found<=0)
{
cout<<"Sorry, the letter \""<<inputChar<<"\" is not in the word.";
mistakes++;
}
else
{
score=score+chanscor*(MAXGUESS-mistakes);
cout<<"\n""\t"<<"Your score now is: "<<score<<"\n";
if(found==1)
cout<<"Yes, there is one letter \""<<inputChar<<"\" in the word.";
else cout<<"Yes, there are "<<found<<" letters \""<<inputChar<<"\" in the word.";
playing=false;
for(i=0;i<length;i++)
playing=playing||!display[i];
if(!playing)
{
cout<<"You found all the letters in the word \""<<word<<"\".";
printMistakes(mistakes);
p=1;
return p;
}
}
}
}
if(mistakes>=MAXGUESS)
{
cout<<"The word was \""<<word<<"\".";
p=0;
return p;
playing=false;
}
}
}
static void printMistakes(int n)
{
if(n<=0)
cout<<"You didn't make any mistakes. Awesome!";
else if(n==1)
cout<<"You made only one mistake. Excellent!";
else
cout<<"You made only "<<n<<" mistakes. Nice!";
}
void quitfunc(void)
{
clrscr();
cout<<"\t""\t""\t"<<"The Lunatic Asylum, Las Vegas"<<"\n""\n";
cout<<"--------------------------------------------------------------------------------"<<"\n";
cout<<"\t""\t""\t"<<"C++ Gaming Cum Gambling Machines"<<"\n""\n";
cout<<"--------------------------------------------------------------------------------"<<"\n""\n";
cout<<"\n""\n"<<"\t""Thank You for using the C++ Gaming Cum Gambling Machine"<<"\n""\n""\t"<<" We hope you enjoyed gambling with us.";
for(int i=0;i<1999999999;i++)
{
}
exit(0);
}
int rps(long int amt)
{
long int bet;
int ch, z, k;
char y, p;
l3:
clrscr();
cout<<"\t""\t""\t"<<"The Lunatic Asylum, Las Vegas"<<"\n""\n";
cout<<"--------------------------------------------------------------------------------"<<"\n";
cout<<"\t""\t""\t"<<"C++ Gaming Cum Gambling Machines"<<"\n""\n";
cout<<"--------------------------------------------------------------------------------"<<"\n""\n";
cout<<"\t""\t""\t""\t"<<"ROCK, PAPER, SCISSORS"<<"\n""\n";
if(amt==0)
{
cout<<"\t""\t"<<"Sorry you have no money left. Its time for you to leave.";
l8:
for(int i=0;i<1999999999;i++)
{
}
quitfunc();
}
cout<<"\t""\t""\t""\t"<<"Instructions"<<"\n""\n";
cout<<"Enter 1 for rock"<<"\n"<<"Enter 2 for scissors"<<"\n"<<"Enter 3 for paper"<<"\n";
cout<<"The first one to reach 10 points is the winner"<<"\n";
cout<<"Win ensures double payback of the bet money. Defeat results in complete loss of bet money."<<"\n";
cout<<"Place your bet money: ";
l7:
cin>>bet;
if(bet>amt)
{
cout<<"Sorry you do not have that much money. Please bet a lower amount";
goto l7;
}
cout<<"\n""\n""\t""\t""\t"<<"THINK YOU CAN BEAT THE MACHINE..."<<"\n""\n";
cout<<"Enter y to proceed to the game ";
cin>>y;
clrscr();
cout<<"\t""\t""\t"<<"The Lunatic Asylum, Las Vegas"<<"\n""\n";
cout<<"--------------------------------------------------------------------------------"<<"\n";
cout<<"\t""\t""\t"<<"C++ Gaming Cum Gambling Machines"<<"\n""\n";
cout<<"--------------------------------------------------------------------------------"<<"\n""\n";
cout<<"Your money: $"<<(amt-bet)<<"\n""\n";
int a=0, b=0, win=0;
l1:
while(win!=10)
{
cout<<"Score = "<<a<<"\t""\t""\t""\t""\t""\t"<<"Score = "<<b<<"\n";
cout<<" You"<<"\t""\t""\t""\t""\t""\t"<<"Machine"<<"\n";
l2:
cin>>ch;
if(ch==1)
cout<<"Rock";
else if(ch==2)
cout<<"Scissor";
else if(ch==3)
cout<<"Paper";
else
{
cout<<"Wrong entry. Enter 1 for Rock, 2 for Scissor and 3 for Paper: ";
goto l2;
}
randomize();
z=random(3)+1;
if(z==1)
cout<<"\t""\t""\t""\t""\t""\t""\t""Rock";
else if(z==2)
cout<<"\t""\t""\t""\t""\t""\t""\t""Scissor";
else
cout<<"\t""\t""\t""\t""\t""\t""\t""Paper";
cout<<"\n""\n";
if(ch==z)
cout<<"\n"<<setw(4)<<"Looks like both you and the machine think alike. No points for anyone.";
else
{
cout<<"\n""\t""\t";
switch(ch)
{
case 1:
if(z==2)
{
cout<<"Rock beats scissor! Point for Player.";
a++;
}
else if(z==3)
{
cout<<"Paper beats rock! Point for Machine.";
b++;
}
break;
case 2:
if(z==3)
{
cout<<"Scissor beats paper! Point for Player.";
a++;
}
else if(z==1)
{
cout<<"Rock beats Scissor! Point for Machine.";
b++;
}
break;
case 3:
if(z==1)
{
cout<<"Paper beats Rock! Point for Player.";
a++;
}
else if(z==2)
{
cout<<"Scissor beats paper! Point for Machine.";
b++;
}
break;
}
}
if(a>b)
win=a;
else if(b>a)
win=b;
else
win=a;
cout<<"\n""\n";
goto l1;
}
cout<<"\n""\n";
if(a==10)
{
cout<<"Congratulations! You just beat the Machine!";
amt+=bet;
}
else if(b==10)
{
cout<<"Aww, You just got served by the Machine. Better luck next time.";
amt-=bet;
}
cout<<"\n""\n";
cout<<"You now have $"<<amt<<"\n"<<"Do you want to play again??(y/n) ";
l4:
cin>>p;
if(p=='y' || p=='Y')
goto l3;
else if(p=='n' || p=='N')
{
cout<<"\n"<<"Enter 0 if you want to play another game in the Machine"<<"\n"<<"Enter 1 if you want to leave the Machine"<<"\n";
l6:
cin>>k;
if(k==0)
{
return amt;
}
else if(k==1)
{
goto l8;
}
else
{
cout<<"\n"<<"Wrong Entry. Please enter 0 or 1: ";
goto l6;
}
}
else
{
cout<<"\n"<<"Wrong entry. Please enter y or n: ";
goto l4;
}
}
int roulette(long int amt, int y)
{
int n, x, ch, a, b=0, z;
char t;
y=0;
cout<<"\t""\t""\t"<<"The Lunatic Asylum, Las Vegas"<<"\n""\n";
cout<<"--------------------------------------------------------------------------------"<<"\n";
cout<<"\t""\t""\t"<<"C++ Gaming Cum Gambling Machines"<<"\n""\n";
cout<<"--------------------------------------------------------------------------------"<<"\n""\n";
cout<<"\t""\t""\t""\t"<<"RUSSIAN ROULETTE"<<"\n""\n"<<"\t""\t""\t""\t"<<"Instructions"<<"\n""\n"<<"To bet on odd numbers, enter 1"<<"\n";
cout<<"To bet on even numbers, enter 2"<<"\n"<<"To bet on a particular number, bet 3"<<"\n";
cout<<"Win on an odd or even situation ensures double payback of bet money."<<"\n";
cout<<"Win on a single number bet situation ensures payback of 35 times the bet money." <<"\n";
cout<<"Loss in all situations results in complete loss of bet money."<<"\n""\n";
l2:
if(amt==0)
{
cout<<"Sorry you have no money left. Its time for you to leave.";
l5:
for(int i=0;i<1999999999;i++)
{
}
quitfunc();
}
cout<<"Your money: "<<amt<<" $"<<"\n""\n";
cout<<"Place your bet: ";
l4:
cin>>ch;
if(ch==3)
{
cout<<"Looks like someone is feeling very confident today. Which number do you want to bet on? ";
cin>>x;
}
cout<<"\n";
if(ch>3)
{
cout<<"Wrong Option. Enter either 1, 2 or 3: ";
goto l4;
}
l1:
cout<<"Place your money: $";
cin>>n;
cout<<"\n";
if(n>amt)
{
cout<<"Sorry you do not have that much money. Please bet a lower amount"<<"\n";
goto l1;
}
cout<<"\n";
cout<<"Rolling the roulette table....";
cout<<"\a""\a""\a""\a""\a""\a""\a""\n";
randomize();
a=random(36);
for(int i=0;i<1999999999;i++)
{
}
cout<<"The winning number is "<<a<<" !";
switch(ch)
{
case 1:
if(a%2!=0)
{
b=n;
cout<<"\n"<<"Winner Winner Chicken Dinner!! You've won "<<b<<" $ !!";
}
else
{
b=(-1)*n;
cout<<"\n"<<"Tough luck! You just lost "<<(-1)*b<<" $ !";
}
break;
case 2:
if(a==0)
{
b=(-1)*n;
cout<<"\n"<<"Tough luck! You just lost "<<(-1)*b<<" $ !";
}
else if(a%2==0)
{
b=n;
cout<<"\n"<<"Winner Winner Chicken Dinner!! You've won "<<b<<" $ !!";
}
else
{
b=(-1)*n;
cout<<"\n"<<"Tough luck! You just lost "<<(-1)*b<<" $ !";
}
break;
case 3:
if(a==x)
{
b=34*n;
cout<<"\n"<<"Whoa! Looks like luck is on your side today. You've won "<<b<<" $ !!";
}
else
{
b=(-1)*n;
cout<<"\n"<<"Sorry mate. Luck's not favouring you today eh?. You just lost "<<(-1)*b<<" $ !";
}
break;
}
amt+=b;
cout<<"Wanna play again?? (y/n)"<<"\t";
l3:
cin>>t;
if(t=='y'|| t=='Y' )
{
cout<<"\n";
goto l2;
}
else if(t=='n' || t=='N')
{
cout<<"\n";
cout<<"Your money now is: $"<<amt;
cout<<"\n";
cout<<"Enter 1 if you want to play another game in the machine."<<"\n";
cout<<"Enter 2 if you want to leave the machine."<<"\n";
cout<<"What do you want to do? ";
l6:
cin>>z;
if(z==1)
goto l7;
if (z==2)
goto l5;
else if(z>2 || z<1)
{
cout<<"\n";
cout<<"Wrong entry. Enter 1 or 2 ";
goto l6;
}
}
else
{
cout<<"Wrong Option. Enter y or n ";
goto l3;
}
l7:
return amt;
}
void main()
{
char name[50], xzg[10][10]={"null", "Mr. ", "Mrs. ", "Ms. ", "Dr. ", "Rev. "};
long int money;
int r=0, ch, pre;
cout<<"\t""\t""\t"<<"The Lunatic Asylum, Las Vegas"<<"\n""\n";
cout<<"--------------------------------------------------------------------------------"<<"\n";
cout<<"\t""\t"<<"Welcome to the C++ Gaming Cum Gambling Machines"<<"\n""\n";
cout<<"--------------------------------------------------------------------------------"<<"\n""\n";
cout<<"Please choose your prefix: "<<"\n"<<"1 for Mr."<<"\n"<<"2 for Mrs."<<"\n"<<"3 for Ms."<<"\n"<<"4 for Dr."<<"\n"<<"5 for Rev."<<"\n";
l3:
cin>>pre;
if(pre>5 || pre<1)
{
cout<<"Wrong Entry. Please enter 1, 2, 3, 4 or 5: ";
goto l3;
}
cout<<"Please enter your name: "<<xzg[pre];
gets(name);
cout<<"\n""\n""\n";
cout<<"Place all your money on the table. How much are you willing to gamble?"<<"\n";
cout<<"$ ";
cin>>money;
for(int i=0;i<1999999;i++)
{
}
clrscr();
l1:
cout<<"\t""\t""\t"<<"The Lunatic Asylum, Las Vegas"<<"\n""\n";
cout<<"--------------------------------------------------------------------------------"<<"\n";
cout<<"\t""\t"<<"Welcome to the C++ Gaming Cum Gambling Machines"<<"\n""\n";
cout<<"--------------------------------------------------------------------------------"<<"\n""\n";
cout<<"\t""\t""\t"<<"Welcome "<<xzg[pre]<<name<<"\n""\n";
cout<<"Your money = $"<<money;
cout<<"\n""\n";
cout<<"To play Hangman, Enter 1"<<"\n";
cout<<"To play Roulette, Enter 2"<<"\n";
cout<<"To play Rock Paper Scissor, Enter 3"<<"\n";
cout<<"To leave the machine, enter 4"<<"\n";
cout<<"What would you like to do? ";
l2:
cin>>ch;
switch(ch)
{
case 1:
clrscr();
money=hangman(money);
clrscr();
break;
case 2:
clrscr();
money=roulette(money,r);
clrscr();
goto l1;
break;
case 3:
clrscr();
money=rps(money);
clrscr();
goto l1;
break;
case 4:
quitfunc();
break;
default:
cout<<"Wrong Entry. Please enter 1, 2, 3 or 4: ";
goto l2;
break;
}
getch();
}
We have to submit the project in a couple of week so Im really desperate for help here.
Thanks.