Like Tree1Likes

No errors but still a problem.

This is a discussion on No errors but still a problem. within the C++ Programming forums, part of the General Programming Boards category; So, I'm having another issue with my little text based game I am making. I've corrected all the mistakes in ...

  1. #1
    Registered User
    Join Date
    Jul 2011
    Posts
    10

    Angry No errors but still a problem.

    So, I'm having another issue with my little text based game I am making. I've corrected all the mistakes in my coding (i get no build errors) however when I run the game I cannot access certain areas. I think I have messed something up on either player.cpp, player.h, or the "Motel" portion of suburbs.cpp because before I wrote those codes everything worked as it should. Below is a link to my files because it put them in this tread would be just a bit to much to read. Here's hoping someone will take the time to d/l them and help me because I have no clue what I've done... Also, I'm new here so if this is the wrong way to post my problem (i.e. no one in their right mind will download someone elses code) then someone let me know so i can correct it and get some help

    SaveTheGinger

    WARNING: My game contains strong language that is not suitable for those easily offended. If you choose to d/l to help me, be forewarned. I do not wish to offend anyone that is trying to help me.
    Last edited by d20junkie; 07-19-2011 at 12:06 PM. Reason: cause i'm a noob

  2. #2
    Registered User
    Join Date
    Jun 2011
    Posts
    2,243
    I am not able to download/check out your file right now, as I'm at work. This line from your last post concerns me a little;

    I am new at programming but have always wanted to learn and figured this would be a good tool.
    Depending on how new you are, a text-based game may be best put on hold until you get more familiar with the language. However, if you really feel that you're ready, here is some advice. Take it for what it's worth.

    In programming, troubleshooting/debugging skills are just as important as coding skills and problem solving skills. Figuring the problem out on your own will be the most valuable lesson you can learn from whatever mistakes were made.

    Did you try putting temporary print statements in your code? You can use these to see if certain blocks of code are executed or bypassed, as well as to ensure that any variable values match what you expect for that location in the code.

    Running through debug also helps you see what is happening step by step, while keeping an eye on the local variable data. This will often lead you, if not to the problem, then at least to a place where you can start narrowing down what the problem might be.

    I'm sorry I couldn't be of any more help, but I wormed my way through this phase by myself a while back and the lessons I've learned as a result are invaluable.

    WARNING: My game contains strong language that is not suitable for those easily offended.
    I've been there, too!

  3. #3
    Registered User
    Join Date
    Jul 2011
    Posts
    10
    I will say that you are right as far as a text based game being a bit outta my league (i have a stubborn personality that won't let me quit something no matter how hard it is, it's how I learned HTML). It started because I found tutorials online while looking to simply play a text based game. The tutorials themselves aren't the greatest but I'm already picking up bits and pieces as i watch. My first problem, I worked through on my own (after looking up what the errors meant), my second I posted here and was aided. As I check back every little while to see if anyone has found what I've missed, I search my own files modifying this and double checking that just to see if i can correct the problem on my own. As I said, I think I have the problem narrowed down to a few .cpp files.

  4. #4
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,452
    Before checking the code, here are some tips and useful information:
    - The .ncb file is not necessary to bundle along. It contains IntelliSense information all will be recreated by the IDE automatically.
    - The Debug and Release folders can be omitted too since they contain the compiled code and can be re-created by compiling.
    - You should upgrade to VS2010.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Based on the post, I suspect this is something I shouldn't download at work, so again without (yet) looking at the code:
    Another big part of troubleshooting is "accurately writing down the problem". You say you can't access certain areas. Is that because when you are in a nearby area the path to the forbidden zone isn't mentioned? It is mentioned but if you type "e" you crash? (Can you type "e" and go there even if it isn't mentioned?)

    In the first case, that suggests that there may be an issue with your game map building, or perhaps with the actual data itself (maybe you forgot to put the doorway in in the first place). Without looking at how you do it, unfortunately I can't get very specific about what could be wrong.

  6. #6
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,452
    Problem:
    - void main shall be int main.
    - Do not use C-style strings. For example, char name[32] should be std::string name.
    - Using upper-case names for classes is not recommended. They are reserved for macros, usually.
    - This is good advice: http://sourceforge.net/apps/mediawik...arameter_names
    - Do not put declarations into some global header file. Separate everything into source files and their complementing header file. For example, Suburbs.cpp and Suburbs.h, not Suburbs.cpp and Globals.h.
    - Never use cin >> with a char array. This is a ticking time bomb (see buffer overrun). Use std::string with (std::cin >> or std::getline).
    - Read up on references instead of using pointers all the time.
    - Avoid global variables. Prefer passing them around as arguments if you must.
    - bool hcomplete = false(); <-- false is not a type, hence the parenthesises there really shouldn't be there.
    - Why does Apartment return anything when you always return true?
    - You are missing const correctness. A topic to study, I believe.
    - Don't use strcpy. It's unsafe (see buffer overruns). Instead use std::string with the normal assignment operator.

    Well, you should probably start with this before expanding on your code.
    And you might also tell us how to reproduce the bug, if you don't mind.
    Last edited by Elysia; 07-19-2011 at 01:16 PM.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #7
    Registered User
    Join Date
    Jul 2011
    Posts
    10
    I suspect this is something I shouldn't download at work
    it IS just a text based game so I wouldn't see the harm in downloading it. it only has one or two "dirty" words anyway

    The problem, it the best way i can describe it, i was following a tutorial i found to make text based games. after seeing your posts, i would assume i'm using outdated code. as i followed the tutorial it asked to make a starting area for the player, an area that the player could repeatedly come back to in order to obtain new quests or go to town for supplies. I chose to call this place "the apartment". now, after a while in the tutorial, i had made the title screen "the apartment", and "the suburbs" (town). options from "the apartment" allowed you to travel to "the suburbs" and back. everything worked fine (after fixing a few errors). once i continued the tutorial, i was asked to make an inn for the town ("motel" for "the suburbs") and define the player. this is where everything went wrong. after fixing a few errors and finally getting a successful build i tried to run my game. because of something i did i can no longer travel to "the suburbs". it will allow me to open the game (see title text) and, after hitting enter, see "the apartment" text and options, i can even exit the game (using option 10) but when i type option 1 (the option for "the suburbs") it takes me to the next line down and i can input nothing further. As i said, just before i added the "motel" and defined the player, everything worked fine. I hope that helps to better define the problem.

    it's probably worth noting that i don't know c++, i thought that this would teach me but i think i'm drowning.... maybe i should find that "hello world" thing everyone is talking about...
    Last edited by d20junkie; 07-19-2011 at 02:03 PM. Reason: hello world

  8. #8
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,452
    Well, you should find your problems pretty quickly with a debugger (VS has one; press F5).

    For one:
    while(choice != 5);
    should be
    while(choice != 5)

    while(answer[0] !='p' || answer[0] !='l')
    should be
    while(answer[0] !='p' && answer[0] !='l')
    (Of course, this is wrong too, since you should use std::string here.)

    You also have some problem with your project configuration. Click the arrow next to Debug, choose configuration manager and inside select "Debug" instead of "Release" on your project.

    Also...
    bool hcomplete = false();
    This is not valid C++. It's a Visual Studio extension.
    It should be
    bool hcomplete = false;
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #9
    Registered User
    Join Date
    Jul 2011
    Posts
    10
    I'm using VS, is that a problem? I'm only using it cause that's what the guy on the tutorial is using...

    i'm going through and doing the "hello world" stuff.... i guess Save The Ginger will have to wait, at least till i learn more and/or u guys help me through this hump.
    Last edited by d20junkie; 07-19-2011 at 03:02 PM.

  10. #10
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,452
    Quote Originally Posted by d20junkie View Post
    I'm using VS, is that a problem? I'm only using it cause that's what the guy on the tutorial is using...
    It's not a problem. You need to learn how to use it properly. That is all.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #11
    Registered User
    Join Date
    Jul 2011
    Posts
    10
    OMG! Elysia, you are my effen hero!!! now the only problem is that when i get to the "motel", no matter what i input, it brings me straight back to the "suburbs". wis that the "std::string name" thing you were talking about? or did i just get lost again?

    i took out all the ()'s and the extra ";"'s then changed the || to && like you said
    Last edited by d20junkie; 07-19-2011 at 03:08 PM.

  12. #12
    Registered User
    Join Date
    Jun 2011
    Posts
    2,243
    OMG! Elysia, you are my effen hero!!!
    Will this be added to the signature?

  13. #13
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,452
    std::string has nothing to do with it.
    When your function ends, you return to outside the motel, and all paths simply end with going out of the function.
    This is simply a logic problem.

    Suburbs calls Motel.
    Motel awaits input.
    User inputs l or p.
    Motel returns.
    Suburbs loop and asks for input.

    You also seem to check for 'y' and 'n' in if statements below, but your "loop" wants 'l' or 'p'.

    Quote Originally Posted by Matticus View Post
    Will this be added to the signature?
    No promises on that one
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  14. #14
    Registered User
    Join Date
    Jul 2011
    Posts
    10
    oh wow... i didn't even notice... originally i had "yes" or "no" answers instead of "pay" or "leave".... i guess i forgot to change them.... everything works perfectly now!!! elysia... can we have little programmer babies together that will be so much smarter than me? (sorry if that ends up coming across offensive, i'm just stoked that it's all working now). you're my freakin programming god! if i change all the "p"'s and "l"'s to "pay" and "leave"... then the player would have to type in the full word, right?
    Last edited by d20junkie; 07-19-2011 at 03:21 PM.

  15. #15
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,452
    Quote Originally Posted by d20junkie View Post
    elysia... can we have little programmer babies together that will be so much smarter than me? (sorry if that ends up coming across offensive, i'm just stoked that it's all working now). you're my freakin programming god!
    o_O
    Considering my disposition towards kids, I don't think said event would occur/[be possible] in any near future!
    Perhaps you'll find some (other) smart programming gal who you'll end up marrying some day
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. problem with errors
    By mark103 in forum C++ Programming
    Replies: 3
    Last Post: 04-05-2011, 11:00 AM
  2. Problem using map<> - Compile Errors
    By intruder in forum C++ Programming
    Replies: 15
    Last Post: 04-19-2006, 11:56 AM
  3. Replies: 12
    Last Post: 06-08-2005, 11:23 AM
  4. build errors and cin problem
    By steve043 in forum C++ Programming
    Replies: 5
    Last Post: 04-04-2004, 12:56 PM
  5. problem solving compiler errors
    By Jan79 in forum C++ Programming
    Replies: 1
    Last Post: 07-02-2003, 10:59 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21