![]() |
|
[C] Text adventure help - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [C] Text adventure help (/showthread.php?tid=5148567) |
Text adventure help - LaliKinux - Jan 26, 2016 So i'm creating a basic text adventure to help with my skills. I'm running into a problem with an if-else statement. It keeps wanting to run the Code #include <iostream>Excuse the cin.get()'s. Im using visual studios so it's the only way to keep the console up?... Anywho, it keeps giving me the Congrats line no matter what I type in. Why is my else statement not working? Also, is there a way I can keep the console up without having to use cin.get() in every single statement/function? It's really annoying imo * - Goodies - Jan 26, 2016 This is the issue. PHP Code try: PHP Code Also, I just use system("pause") but whatever works. * - 6577657534735 - Jan 26, 2016 Set breakpoints to keep the console open at whatever point without moving forward I always have the final "return 0" in main breakpointed. * - Goodies - Jan 26, 2016 Also, you might want to use transform to make sure the input will be caught. For example, if I type "Easy", it will not work because only "easy" is correct. Instead of doing something stupid like: if (... "easy" || ... "Easy" || "EAsy" ... etc) You can do something like: PHP Code * - LaliKinux - Jan 26, 2016 Thanks! Really helped a lot mate * - 0xDEAD10CC - Jan 26, 2016 (Jan 26, 2016 06:26 PM)Goodies Wrote: Also, you might want to use transform to make sure the input will be caught. For example, if I type "Easy", it will not work because only "easy" is correct. Instead of doing something stupid like: Why would you use std::find() when std::set::find() already exists? http://www.cplusplus.com/reference/set/set/find/ I didn't like the usage of system("pause") thrown into the example either, not really necessary to use it in snippets for learning material, but you haven't included the proper header to use it either (<cstdlib>) * - Goodies - Jan 26, 2016 (Jan 26, 2016 08:49 PM)0xDEAD10CC Wrote: Why would you use std::find() when std::set::find() already exists? http://www.cplusplus.com/reference/set/set/find/ 1) I'm brand new to this. How would you use that? just like: std::set<std::string> myset = {"a", "b", "c"}; myset.find("b") ? 2) How do you do it? std::cin.getline()? * - 0xDEAD10CC - Jan 26, 2016 If I ever need to std::cin.get() works completely fine for me. I hardly ever have a reason to do so in a production application though, and you really don't see it very often anyways. That's batch stuff... * - Goodies - Jan 26, 2016 (Jan 26, 2016 11:10 PM)0xDEAD10CC Wrote: If I ever need to std::cin.get() works completely fine for me. I hardly ever have a reason to do so in a production application though, and you really don't see it very often anyways. That's batch stuff... Right. Do you not do a lot of console applications? or do you test from command line? Or are you just focused on debugging etc so CLI output is not really relevant? I would assume so. * - 0xDEAD10CC - Jan 26, 2016 (Jan 26, 2016 11:28 PM)Goodies Wrote: Right. Do you not do a lot of console applications? or do you test from command line? Or are you just focused on debugging etc so CLI output is not really relevant? I would assume so. There are other ways to debug without writing output to the console buffers. Visual Studio comes pre-packaged with a fully equipped debugger that saves more time if you actually know how to use it properly. There's really no reason to keep a line of code like that in a production program though, console or not. If you open up a command prompt in Windows, type the executable name, cmd.exe remains running and you can see output even after the program has terminated. Chances are unless the program takes no command line arguments, or if you create a shortcut that invokes it already with specific arguments, you're going to invoke the program that obvious way anyways. |