Hello guys, Ron here...im going to start my IT lessons next year but I already started learning some basics in C++...actually, I tried making a Hangman game already but there's something wrong...My loop is incorrect...please help me...so here is my first ever code..
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<math.h>
void main()
{char name[20],Lvl1[4]="ENVY",letter;
int trial=3,pts=0;
cout<< " -------+++++++-------+++++++-------+++++++-------+++++++-------+++++++-------";
cout<< "\n";
cout<<"\t\t --------------------------------------------\n";
cout<<"\t\t | # # # # # #### # # # # # |\n";
cout<<"\t\t | # # # # ## # # ## ## # # ## # |\n";
cout<<"\t\t | #### ##### # # # # ## # # # ##### # # # |\n";
cout<<"\t\t | # # # # # ## # # # # # # # ## |\n";
cout<<"\t\t | # # # # # # ### # # # # # # |\n";
cout<<"\t\t --------------------------------------------\n\n";
cout<< " -------+++++++-------+++++++-------+++++++-------+++++++-------+++++++-------";
cout<< "\n";
cout<< "\nAbout the game: Hangman is a game that will let you play with the";
cout<< "\ncomputer in which it will generate word/words to be guessed by the";
cout<< "\nplayer by entering letters one at a time. If the player guesses a";
cout<< "\nright letter,it will be placed in its right position.\n";
cout<< "\nGuess with less than 4 mistakes, then you win the game";
cout<< "\nOtherwise, you lose.";
cout<< "\nPlease Fill this up first\n";
cout<< "\nPlayer Name:";
gets(name);
clrscr();
cout<< "Lets begin!";
cout<< "\nPlayer Name:"<<name;
cout<< "\n\t\t\t\t===================";
cout<< "\n\t\t\t\tWelcome to Level 1!";
cout<< "\n\t\t\t\t===================";
cout<< "\nHint: This is another term used to refer to someone who's jealous- _ _ _ _";
cout<< "\nPoints Earned:"<<pts;
cout<< "\nPlease enter a letter:";
cin>>letter;
do
{
for(int pos=0;pos<4;pos++)
if(letter==Lvl1[0])
{cout<< "Nice guess!";
cout<< "\nYou earned 10 points!";
pts=pts+10;
gotoxy(68,6);
cout<<Lvl1[0];}
else if(letter==Lvl1[1])
{cout<< "Nice guess!";
cout<< "\nYou earned 10 points!";
pts=pts+10;
gotoxy(70,6);
cout<<Lvl1[1];}
else if(letter==Lvl1[2])
{cout<< "Nice guess!";
cout<< "\nYou earned 10 points!";
pts=pts+10;
gotoxy(72,6);
cout<<Lvl1[3];}
else if(letter==Lvl1[3])
{cout<< "Nice guess!";
cout<< "\nYou earned 10 points!";
pts=pts+10;
gotoxy(74,6);
cout<<Lvl1[3];}
else
{cout<< "Oops!That letter is not part of the word!";
trial=trial-1;
cout<< "You have "<<trial<<" tries left";}
if(trial==0)
cout<< "You are dead, GAME OVER";
break;
}
while(pts<30);
\\this is where the player gets to the next level,i plan to use goto statement\\
}