Hello, I'm trying to capture letters entered by user into an array using classes. Although I'm having some unknown difficult issues:

//main .cpp file.
int main()
{

char guess = 'a';
hangman game1; 

game1.getbuffer(guess);

guess = 'b';
game1.getbuffer(guess);
return 0;
}

at the minute as you can see I'm using pre set values, to try and get it working right, although i'm 100% certain the problem doesnt lie here I thought I'd post it anyway.

Heres the implemenation of the function:

void hangman::getbuffer(char a)
   {
	//takes in the letters
	int i;
	for ( i= 0 ;i < 4 ; i++)
		buffer[i] = a; 

   //spits out the letters
	for (i= 0 ;i < 4 ; i++)
		cout <<buffer[i];
}

<< moderator edit: fixed [code][/code] tags >>

The code works , but its the output i dont like, since it prints 4xa's and 4xb's , not 1 a and 1 b.

Thanks

John

Yes, it should be printing 4 as and 4 bs.
Your code, in english, says the following:

Put an 'a' into four entries of an array.
Display the entries in the array.

What's the problem?

Yes, it should be printing 4 as and 4 bs.
Your code, in english, says the following:

What's the problem?

Yeh I know, I'm trying to figure out how to get it just to fil 1 slot up and print 1 a out and 1 b out. I've tried taking the loop out but it crashes then lol

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.