Hello MobMessenjah,
Add some blank lines to your code to make it more readable.
You could use the "<random>" header file and 1 of the RNGs there, but that may not solve the problem.
In the
else if (guess == secretNumber)
you missed 2 variables.
1 2 3 4 5 6 7 8 9 10
|
cout <<
"\n\n************************************************************************\n"
"\t\t\tStarting Round: " << round <<
"\n************************************************************************\n";
guess = 0;
secretNumber = 0;
tries = 0;
hiVal = 100;
loVal = 1;
|
By not setting the last 2 variables they have their last value, so in the next round it does not work. Sometimes it may work if your new number is far enough away to change 1 of the values for "loval" or "hival".
Usually with this type of program the first computer guess would be 50 and the 2nd guess would be 1/2 of 50 either less than or greater than. In the range of 1 to 100 it should only take 7 tries for the computer to guess the number.
When I added the 2 variables and reset "loval" and "hival" it appears to work, although I have not run the program to its conclusion.
You do not need a "cout" statement for each line that you output. The example shows how you can use insertion operator (<<) to chain everything together into 1 statement. And if each line is only a quoted string it will be considered 1 string.
Also be careful using the tab (\t). At the beginning of a string it is not generally a problem. Any (\t) after some text may not space out the way that you want. I tend to like using
std::string(20, ' ')
. This is the fill ctor of the string class. the first parameter is how many you want and the 2nd parameter if the character to fill with. Here it is a space, but you can use any character that will print on the screen. I find it better than using (\t).
You have defined several variables as "unsigned int" consider
using uInt = unsigned int;
and then in "main"
uInt round{ 1 };
. Also you do not need to use the " = 1". Just use the {}s. Empty the compiler will use the proper form of (0)zero needed or you can put anything between the {}s that you need including a quoted string for a "std::string". Much easier to type.
Andy