Advertisement

Noob Here, need help with "Guess My Number"

Started by June 29, 2005 11:45 AM
29 comments, last by Washu 10 years, 3 months ago
EDIT: Oops never mind, ignore what I said before.

Also, don't you want while(ComGuess != theNumber)? Because you want to end the loop when the player guesses right.
-----------------------------Play Stompy's Revenge! Now!
Quote:
Original post by chris_bell
thanks for that, i wasn't really sure what to do about obtaining a value each time for comGuess.
now for some reason, though, i'm getting an error on the 'while' line...though i see nothing wrong with it.

} while (comGuess == theNumber);

seems fine to me...


while statements do not have an end ';'

so your line should look like "} while (comGuess == theNumber)" but you probably want to make that a "!=" otherwise it will only continue if the computer gets it right rather than continuing until the computer gets it right.
Advertisement
oh, good call on the != . though that while line still gives an error, even when its } while (comGuess != theNumber).
And it's the computer guessing, not the player. That was the assignment.
just got the last message while posting. Thanks for the help :D.
Noobs gotta start somewhere lol

EDIT: Hmm..... wow. STILL getting an error.

Line currently looks like so:

} while (comGuess != theNumber)
What is the error you are getting?
Quote:
Original post by jperalta
[while statements do not have an end ';'


while statements don't, but do-while statements do. The closing ';' is required.
Advertisement
Quote:
Original post by Dave Hunt
Quote:
Original post by jperalta
[while statements do not have an end ';'


while statements don't, but do-while statements do. The closing ';' is required.


I actually put the same thing down, and then checked it in my C++ book. To my suprise, Do-While statements actually have a semi-colon.

-----------------------------Play Stompy's Revenge! Now!
i don't know if this is what is causing your error or not, but you really should have a return 0; at the very end of the int main() function.

vc++ 6 is just giving me a warning about it, but other compilers might not allow it.

edit: also, while i can compile it, you have some logic errors as well.
Charles Reed, CEO of CJWR Software LLC
now don't use this unless you understand how it works, but here is a fully functional version.

// Guess My Number 3.0// Have computer guess your number#include <iostream>#include <cstdlib>#include <ctime>using namespace std;int main(){	int theNumber;	int comGuess;	int tries = 0;	int lowest = 1;    //the lowest number the computer should guess 	int highest = 100; //the highest number the computer should guess	cout << "\tWelcome to Guess My Number 2.0!\n\n";	cout << "Please enter a number to be guessed: ";	cin >> theNumber;	do{		comGuess = (highest + lowest)/2;		cout << "\n\nPress Enter to see the Computer's guess...";		cin.get();		//return comGuess;		cout << "The Computer's Guess: " << comGuess << ".\n";		++tries;		if (comGuess > theNumber){			cout << "Too high!\n\n";			highest = comGuess;		}		if (comGuess < theNumber){			cout << "Too low!\n\n";			lowest = comGuess;		}	} while (comGuess != theNumber);	cout << "\nThat's it! The Computer got it in " << tries << " guesses!\n";	return 0;}


remember, learning is the most important part, regardless of what level of learning you're at.
Charles Reed, CEO of CJWR Software LLC
sorry for the late response, but i had to run out the house. Thanks for all the replies, i'll study that program and learn from it CJWR. I'm in it for the learning, that's why i didn't just jump to chapter 3 when I couldn't figure this out from the start.

Again, thanks. For a problem with such a simple program it's nice to know you guys are still passionate about helping. Looks like I'll be hanging around here for a while and learning.

This topic is closed to new replies.

Advertisement