alright so my friend helped me with the "check" code a bit...
but the "game" kinda craps out when the user puts in a correct letter.
does any one want to tell me what is wrong and how to fix it so that instead of crapping out it puts the answer in the right spot?
/*
*/
#include
but the "game" kinda craps out when the user puts in a correct letter.
does any one want to tell me what is wrong and how to fix it so that instead of crapping out it puts the answer in the right spot?
/*
*/
#include
[Error: Irreparable invalid markup ('<time.h>') in entry. Owner must fix manually. Raw contents below.]
alright so my friend helped me with the "check" code a bit...
but the "game" kinda craps out when the user puts in a correct letter.
does any one want to tell me what is wrong and how to fix it so that instead of crapping out it puts the answer in the right spot?
<lj-cut text="main function">
/*
*/
#include <time.h>
# include <iostream>
# include <string>
using namespace std;
void draw(int);
void greeting(char &);
void menu(int&);
char *easywords(int);
char *hardwords(int);
char *mediumwords(int);
void blanks(char*, int);
void check(char *,char *, int *,int *, char inputStr[], int *);
void main()
{
//-------------------------initilizes stuff ----------------------------------
char *word, *correctString=" ";
srand( (unsigned)time( NULL ) );
// int right=0, wrong=0, numberInput=0;
char ans = 'y';// sets answer to yes until user changes it
int level = 4; // level set to a choice that is not an option
//-------------------------------greeting---------------------------------------
greeting(ans); // displays the greeting once
//--------------------------------------------------------------------
do // will run until the user doesn't want to play anymore
{
if (ans =='N' ||ans=='n') // if the user dose not want to play then exits the game
break;
//------------menu--------------
menu(level);// displays the menu
//------------------------------
char guess[24]; // store user inputs (avoid duplicate entry)
int right=0, wrong=0, numberInput=0; // sets to zero
switch(level)
{
case 1:{
for (int i= 0; i<26; i++)
guess[i]='\0';
int e=rand()%42;
word = easywords(e); //random number
int length=strlen(word);
draw(wrong);
cout <<endl;
//blanks(correctString,length);
while(wrong <8 && right<length)
{
for (int i=0; i<length; i++)
cout<<"_ ";
// blanks(correctString, length);
check(word,correctString,&right,&wrong,guess,&numberInput);
//draw(wrong);
if(wrong !=8)
draw(wrong);
cout<<"Letter used: \n"<<guess<<endl;
} //end while
if(wrong==8){
draw(wrong);
cout<<" Sorry! You missed."<<endl;
cout<<"The word was: "<<word<<endl;
} //end if
else {
draw(9);
//cout<<"\nCongratulations! You are correct!"<<endl;
cout<<"The word was: "<<word<<endl;
} //end else
}
break;
case 2: {
int m=rand()%22;
for (int i= 0; i<26; i++)
guess[i]='\0';
word = mediumwords(m); //random number
int length=strlen(word);
draw(wrong);
cout <<endl;
//blanks(correctString,length);
while(wrong <8 && right<length)
{
for (int i=0; i<length; i++)
cout<<"_ ";
check(word,correctString,&right,&wrong,guess,&numberInput);
if(wrong !=8)
draw(wrong);
cout<<"Letters used: \n"<<guess<<endl;
cout<<endl;
} //end while
if(wrong==8){
draw(wrong);
// cout<<" Sorry! You missed."<<endl;
cout<<"The word was: "<<word<<endl;
} //end if
else {
draw(9);
//cout<<"\nCongratulations! You are correct!"<<endl;
cout<<"The word was: "<<word<<endl;
} //end else
}
break;
case 3: {
int h=rand()%22;
for (int i= 0; i<26; i++)
guess[i]='\0';
word = hardwords(h); //random number
int length=strlen(word);
draw(wrong);
cout <<endl;
//blanks(correctString,length);
while(wrong <8 && right<length)
{
for (int i=0; i<length; i++)
cout<<"_ ";
check(word,correctString,&right,&wrong,guess,&numberInput);
//draw(wrong);
if(wrong !=8)
draw(wrong);
cout<<"Letter used: \n"<<guess<<endl;
cout<<endl;
} //end while
if(wrong==8){
draw(wrong);
cout<<" Sorry! You missed."<<endl;
cout<<"The word was: "<<word<<endl;
} //end if
else {
draw(9);
//cout<<"\nCongratulations! You are correct!"<<endl;
cout<<"The word was: "<<word<<endl;
} //end else
}
break;
}//end swtich statement
cout<<"Would you like to play again?"<<endl;
cin>>ans;
}while (ans =='y' || ans=='Y');
}//ending currly brace
</lj-cut>
---------------------------------------------------------------------------------------------------
<lj-cut text="check function">/*
checks
*/
# include <iostream>
# include <string>
using namespace std;
void check(char *word,char *correctStr, int *right,int *wrong,
char inputStr[], int *numberInput)
{
char *temp,*temp2,*temp3,input;
int correctFlag=*right;// sets correctFlag to what is located in
int n = 0; //
cout<<endl;
cout<<"\nWhat letter do you guess?"<<endl;
cin>>input;
cout<<endl;
temp3 = inputStr; // sets temp3 to the inputStr
while(*temp3 != '\0') // makes sure that temp3 is not equal to '\0'
{
if(input==*temp3)
{
cout<<"You Guessed this letter already"<<endl;
cout<<correctStr<<endl;
return;
} //end if
temp3++;
}
inputStr[(*numberInput)++] = input;
temp = word;
temp2=correctStr;
while(*temp!='\0')
{
if(input==*temp)
{
*temp2=input;
(*right)++;
n++;
temp++; temp2++;
}
else{temp++; temp2++;}
}//end while
cout<<endl;
cout<<correctStr<<endl;
if(*right == correctFlag)
(*wrong)++;
}
</lj-cut>
i did not put in the other function well because i dont think that they are why my program 'craps out' but then again i dont know whats wrong except i get an error that says <i>myhangman.exe has encountered a problem and needs to close. We are sorry for the inconvenience.</i>
well thank you in advance!
but the "game" kinda craps out when the user puts in a correct letter.
does any one want to tell me what is wrong and how to fix it so that instead of crapping out it puts the answer in the right spot?
<lj-cut text="main function">
/*
*/
#include <time.h>
# include <iostream>
# include <string>
using namespace std;
void draw(int);
void greeting(char &);
void menu(int&);
char *easywords(int);
char *hardwords(int);
char *mediumwords(int);
void blanks(char*, int);
void check(char *,char *, int *,int *, char inputStr[], int *);
void main()
{
//-------------------------initilizes stuff ----------------------------------
char *word, *correctString=" ";
srand( (unsigned)time( NULL ) );
// int right=0, wrong=0, numberInput=0;
char ans = 'y';// sets answer to yes until user changes it
int level = 4; // level set to a choice that is not an option
//-------------------------------greeting---------------------------------------
greeting(ans); // displays the greeting once
//--------------------------------------------------------------------
do // will run until the user doesn't want to play anymore
{
if (ans =='N' ||ans=='n') // if the user dose not want to play then exits the game
break;
//------------menu--------------
menu(level);// displays the menu
//------------------------------
char guess[24]; // store user inputs (avoid duplicate entry)
int right=0, wrong=0, numberInput=0; // sets to zero
switch(level)
{
case 1:{
for (int i= 0; i<26; i++)
guess[i]='\0';
int e=rand()%42;
word = easywords(e); //random number
int length=strlen(word);
draw(wrong);
cout <<endl;
//blanks(correctString,length);
while(wrong <8 && right<length)
{
for (int i=0; i<length; i++)
cout<<"_ ";
// blanks(correctString, length);
check(word,correctString,&right,&wrong,guess,&numberInput);
//draw(wrong);
if(wrong !=8)
draw(wrong);
cout<<"Letter used: \n"<<guess<<endl;
} //end while
if(wrong==8){
draw(wrong);
cout<<" Sorry! You missed."<<endl;
cout<<"The word was: "<<word<<endl;
} //end if
else {
draw(9);
//cout<<"\nCongratulations! You are correct!"<<endl;
cout<<"The word was: "<<word<<endl;
} //end else
}
break;
case 2: {
int m=rand()%22;
for (int i= 0; i<26; i++)
guess[i]='\0';
word = mediumwords(m); //random number
int length=strlen(word);
draw(wrong);
cout <<endl;
//blanks(correctString,length);
while(wrong <8 && right<length)
{
for (int i=0; i<length; i++)
cout<<"_ ";
check(word,correctString,&right,&wrong,guess,&numberInput);
if(wrong !=8)
draw(wrong);
cout<<"Letters used: \n"<<guess<<endl;
cout<<endl;
} //end while
if(wrong==8){
draw(wrong);
// cout<<" Sorry! You missed."<<endl;
cout<<"The word was: "<<word<<endl;
} //end if
else {
draw(9);
//cout<<"\nCongratulations! You are correct!"<<endl;
cout<<"The word was: "<<word<<endl;
} //end else
}
break;
case 3: {
int h=rand()%22;
for (int i= 0; i<26; i++)
guess[i]='\0';
word = hardwords(h); //random number
int length=strlen(word);
draw(wrong);
cout <<endl;
//blanks(correctString,length);
while(wrong <8 && right<length)
{
for (int i=0; i<length; i++)
cout<<"_ ";
check(word,correctString,&right,&wrong,guess,&numberInput);
//draw(wrong);
if(wrong !=8)
draw(wrong);
cout<<"Letter used: \n"<<guess<<endl;
cout<<endl;
} //end while
if(wrong==8){
draw(wrong);
cout<<" Sorry! You missed."<<endl;
cout<<"The word was: "<<word<<endl;
} //end if
else {
draw(9);
//cout<<"\nCongratulations! You are correct!"<<endl;
cout<<"The word was: "<<word<<endl;
} //end else
}
break;
}//end swtich statement
cout<<"Would you like to play again?"<<endl;
cin>>ans;
}while (ans =='y' || ans=='Y');
}//ending currly brace
</lj-cut>
---------------------------------------------------------------------------------------------------
<lj-cut text="check function">/*
checks
*/
# include <iostream>
# include <string>
using namespace std;
void check(char *word,char *correctStr, int *right,int *wrong,
char inputStr[], int *numberInput)
{
char *temp,*temp2,*temp3,input;
int correctFlag=*right;// sets correctFlag to what is located in
int n = 0; //
cout<<endl;
cout<<"\nWhat letter do you guess?"<<endl;
cin>>input;
cout<<endl;
temp3 = inputStr; // sets temp3 to the inputStr
while(*temp3 != '\0') // makes sure that temp3 is not equal to '\0'
{
if(input==*temp3)
{
cout<<"You Guessed this letter already"<<endl;
cout<<correctStr<<endl;
return;
} //end if
temp3++;
}
inputStr[(*numberInput)++] = input;
temp = word;
temp2=correctStr;
while(*temp!='\0')
{
if(input==*temp)
{
*temp2=input;
(*right)++;
n++;
temp++; temp2++;
}
else{temp++; temp2++;}
}//end while
cout<<endl;
cout<<correctStr<<endl;
if(*right == correctFlag)
(*wrong)++;
}
</lj-cut>
i did not put in the other function well because i dont think that they are why my program 'craps out' but then again i dont know whats wrong except i get an error that says <i>myhangman.exe has encountered a problem and needs to close. We are sorry for the inconvenience.</i>
well thank you in advance!
