please help!

I am trying to make a game where it has the computer guess the number you pick and you tell it whether its to High (H) or to Low (L). I can't get this to loop can someone please explain why? Any help would be appreciated.




//Ruben Bedenbaugh
// 09/25/2012
#include<iostream>
#include <cstdlib>
#include <ctime>
using namespace std;

int main()
{
char answer;
char again = 'Y';
srand(static_cast < unsigned int >(time(0)));
int secretN=rand() % 10 +1; // random number seed generator
int tries= 0;
cout << " Pick a number between 1 and 10 and I will Guess it !" <<endl; // random number 1-100



cout << " is" << secretN <<" your secret number" <<" or is it to Higher or to Lower? > (H/L)" << endl;
cin >> answer;


++tries;



if (answer == 'H')
{
srand(static_cast < unsigned int >(time(0)));
int secretN=rand() % 10 - 2;
cout << " Too HIGH!!!" << endl;
cout << " Try again :)" << endl;
cout << " is " << secretN << " to High or to Low? > (H/L)" <<endl;
cin >> answer;
tries++;


}
if ( answer == 'L' )
{
srand(static_cast < unsigned int >(time(0)));
int secretN=rand() % 10 +1;
cout << " Too LOW!!!"<< endl;
cout << " Try again :)" << endl;
cout << " is " << secretN << " to High or to Low?> (H/L)" <<endl;
cin >> answer;
tries++;
}
if (answer == 'Y') {

cout << "I got it!" <<""<< " tries."<<tries << endl;
cout << "Would you like to try again"<<endl;
cin >> again;
again = 'Y';


while ( answer == 'H' && answer == 'L' && answer == 'Y');

return 0;
system ("pause");
}
}
this should do it for you...

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
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

using namespace std;

int main() {
	start:
	char hOrL, playAgain;
	int num, guess, randStart = 1;
	
	cout << "Pick a number between 1 & 10 and I will guess it!" << endl;
	cin >> num;
	
	srand(time(NULL));
	
	 while(num != guess ) {
		guess = (rand() % 10) + randStart;
		if (guess == num)
			break;
		cout << "Is my guess - " << guess <<" - to high or too low? (H/L): ";
		cin >> hOrL;
		if (hOrL == 'H' || hOrL == 'h')
			randStart--;
		else
			randStart++;
	}
	cout << "I guess your number...it is " << num << "!" << endl;
	cout << endl << "Would you like to play again? (Y/N): ";
	cin >> playAgain;
	
	if (playAgain == 'Y' || playAgain == 'y')
		goto start;
	
	return 0;
}
Topic archived. No new replies allowed.