a game

this is my code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include < iostream>
using namespace std;

int main()
{
	int s = 0;
	char letter;
	char b,i,r,d;
	

	

	for ( int z = 0; z < 5; z = z + 1 )
	{
		cout << "enter a letter? ";
	    cin >>  letter;

		if ( letter == b || i || r || d )
		{
			cout << "correct" << endl;
			s = s + 1;
		}

		else 
			cout << " wrong try agian you still have: " << z << "tries\n";

	}

	if ( s <= 4 )
		cout << "you win" << endl;
	else 
		cout << " you lose" << endl;

		






	return 0;

}


there is something wrong whith this code
Last edited on
Yes.
yes can you tell me were is my mistake bec. i dont know were it is
and thankyou

There is a problem with the code functioning and doing its job however this code now has no errors in it when you run it.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <iostream>
using namespace std;

int main()
{
	int s = 0;
	char letter;
	char b,i,r,d;
	
	
	
	
	for ( int z = 0; z < 5; z = z + 1 )
	{
		cout << "enter a letter? ";
	    cin >>  letter;
		
		if ( letter == b || i || r || d )
		{
			cout << "correct" << endl;
			s = s + 1;
		}
		
		else 
			cout << " wrong try again you still have: " << z << "tries\n";
		
	}
	
	if ( s <= 4 )
		cout << "you win" << endl;
	else 
		cout << " you lose" << endl;
	
	
	
	
	
	
	
	
	return 0;
	
}


The problem was there you put < iostream> so you shouldn't of had that space before iostream. Also when you make your first for loop, instead of z = z + 1 do for ( int z = 0; z < 5; ++z ) And I cant stress this enough, ++z IS NOT I REPEAT IS NOT the same as z++. j = ++z means increment z and then assign z incremented to j. z++ means asign z to j and then increment it.

For your game, from what I can see you are trying to get the user to enter the letter b , i , r or d to complete the program in under 5 trys. Isn't that a bit too hard aswell?

Hope that helps for now,

Arcadiu

Last edited on
if ( letter == b || i || r || d )
should be if ( letter == 'b' || letter == 'i' //...

but would be better gatting a word instead of the single letters
Last edited on
For your game, from what I can see you are trying to get the user to enter the letter b , i , r or d to complete the program in under 5 trys. Isn't that a bit too hard aswell?

It appears that the purpose of the game is to guess what the uninitialized variables will be set to. I wonder what the odds of winning are.
Last edited on
The only winning move is not to play. How about a nice game of chess?
The only winning move is not to play.


WELL SAID!
Topic archived. No new replies allowed.