C++ Input Help

Started by
5 comments, last by Dragonsoulj 16 years, 10 months ago
Here is my game if you want to see what I am talking about: Guess The Number This is for the Windows Console with C plus plus. I have a problem with the input. The game asks for a number, and if a character (letter or symbol) is typed and the player presses ENTER, the game will repeat the last bit of code put on the screen over and over and the player has to close the program to stop the repeating. The problem is that the input type is int, and it doesn't accept characters. The program is supposed to take an integer the player inputs and compare it with another integer, but if the inputted value was a character, the input end of the comparison is messed up. Is there any way to have the input as a char or str and compare it with an integer the same way you can compare an int with an int? (i.e. int x; x <=100) Dragonsoulj
Advertisement
The return value of the >> operator actually enables you to check for invalid input. For example:

int value;if (cin >> value){    // Input is a valid integer}
The Cpp faq lite holds the answer to your problem.

And you can use boost to cast a string to an int.
--------------------Enigmatic Coding
Thanks. I will try that and see if it works.
Quote:Original post by anothrguitarist
The Cpp faq lite holds the answer to your problem.

And you can use boost to cast a string to an int.


is there a similar website for other languages? (i mean similar to cpp-faq-lite)

Beginner in Game Development?  Read here. And read here.

 

Quote:Original post by Alpha_ProgDes
Quote:Original post by anothrguitarist
The Cpp faq lite holds the answer to your problem.

And you can use boost to cast a string to an int.


is there a similar website for other languages? (i mean similar to cpp-faq-lite)


If I said no, what would you deduce about C++? ;) (I honestly can't think of anything that's quite analogous, though.)
Well, thanks for the help everyone gave. It is completely finished, and I am happy with the result. This is my first game, and with knowing only some C++ programming, I got through it. I was using it as practice for what I was learning.

Download the final version here:Click Here

Thanks again,
Dragonsoulj

This topic is closed to new replies.

Advertisement