#include <iostream> 
#include <fstream>
#include <iomanip>
#include <string>
#include <ctime>



using namespace std;

void pickword ();
int wordlength ();
void printout ();
void gameplay ();
void totalgames ();
void replay ();





int main()

{   
    string guessed="";
    string scaffold_top="______"; 
    string scaffold_pole=" |";
    string scaffold_bottom="_|_____";


    string names[350];
    ifstream infile;
    infile.open("smaller2.txt");

    int counter;
    int misguess;
    int z;
    counter=0;
    string container;
    int lines;
    char used;


    do
    {
        getline(infile,container); // stores lines in container
        names[counter] = container;
        counter = counter+1 ;
    }while(counter<343);

    srand ( time(NULL) );
    z=rand()% counter;

cout << names[z] << endl << endl ;  // this keeps track of what name is chosen

cout << names[z].length() << endl;
char line[50];
for (int i =0; i<names[z].length(); i++)


{
    line[i] = '_';
    cout << line[i]<<" ";
}

cout << "Please enter guessing letter."<< endl;

for(int i=0;i<names[z].length();i++)
{
char current_letter = names[z].at(i);
cout << current_letter << endl;
}

cin >> used;
cout<<endl;
cout << endl << endl;
bool found = false;
for(int i=0;i<names[z].length();i++)//guesses correctly and places in line
{
char current_letter = names[z].at(i);
//if statment
if(current_letter==used)// if used = any letter on line, we cout used on line and in used box
{
    line[i] = used;
    guessed = guessed + used;

}
else if(current_letter!=used)
{
    cout << scaffold_top << endl <<scaffold_pole << endl << scaffold_pole <<endl << scaffold_pole <<endl << scaffold_pole <<endl << scaffold_pole << endl <<scaffold_bottom << endl;  
    cout << used << endl;
    guessed = guessed + used;
}
}//create an if statement that checkes whether boolean A is not true
//if not true then add a piece to hangman





//set a boolean A to true




for (int i =0; i<names[z].length(); i++)// prints remaining underscores after correct guesses
{
    cout<< line[i] <<" ";
}

//for (int i=0;i<1; i++)
//
//  if(first!=used)
//  { 
//      line[i] = line[i];
//      cout << endl << used;
//
//  }














return 0;

}

Recommended Answers

All 2 Replies

i cant print out body parts after incorrect guess..please help

Please use code tags. What problem are you having? You can never describe to us a problem in 8 words. We need more detail.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.