Got bored, and whats better than spending your time learning. So I'd thought I'd create something fun,
#include <iostream>
using namespace std;
int main()
{
char array[5] = "John"; //chosen hangman
char array2[5]; //populates with *
char key; //ets a key from the user
int life = 5;
int correct = 0; // flag to 1 if char is in .
int location = 10; //used to determine where the location is
for (int i = 0 ; i < 5 ; i++)
{
array2[i] = '*'; //makes the *
}
for (int j = 0 ; j < 4 ; j++)
{
cout << array2[j]; //prints the *'s
}
while (life !=0) //if lives are greater than 0 carry on else don't
{
cout << "\nplease enter a guess , if you don't guess it right you loose a life" <<endl;
cout << "guess is : " ;
cin >>key; // grab key from user
for( int guess = 0 ; guess < 5; guess++)
if (array[guess] == key)
{
correct = 1; //if the element is found flag a 1 else flag a zero
location = guess;
}
cout << location;
if (correct ==1)
{
cout << "Congradulations, you've found a letter"<<endl;
}
else
{
life --;
cout << "Woah, you just lost a life! , You now have only "<< life << " lives remaining" << endl;
}
}//while loop
return 0;
}
but now I've managed to dig a little hole for myself, once the user as found the chosen char, I want the '*' to be replaced by the found char... Any ideas?