EndGame Function wont endgame, and an OR problem

This is a discussion on EndGame Function wont endgame, and an OR problem within the C++ Programming forums, part of the General Programming Boards category; Okay, so here is what my function looks like. Code: void EndGame() { cin.get(); system("PAUSE"); } and here is an ...

  1. #1
    Registered User
    Join Date
    Jun 2009
    Posts
    5

    Exclamation EndGame Function wont endgame, and an OR problem

    Okay, so here is what my function looks like.

    Code:
    void EndGame()
    {
         cin.get();
         system("PAUSE");
    }
    and here is an example of where it is used

    Code:
        if  ((answer, "no" || "No" || "NO") == 0){
             EndGame();
             }
    i have another problem also. In the above code you see that I have OR statements for if they type NO in a different way, but no matter which way I type it it wont work.

    thanks for any help you can give me.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Why do you think that (answer, "no" || "No" || "NO") could possibly equal 0? What do you even think it does?

  3. #3
    Registered User
    Join Date
    Jun 2009
    Posts
    5
    from what ive learned that means it is true. unless i misread but it worked that way in the program I made that way. although if u arent going to be helpful and just be critical id prefer if u didnt reply cuz it doesnt help anyone

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by StoryGame464 View Post
    from what ive learned that means it is true.
    That means that what is true?

    You've got == 0 later which indicates that you've seen equality before. Why do you not think it should be used here?

  5. #5
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    Quote Originally Posted by StoryGame464 View Post
    from what ive learned that means it is true. unless i misread but it worked that way in the program I made that way.
    C and C++ tend to allow things to appear as if they worked fine, and then sometimes the same kind of code will appear to stop working. This is because C and C++ allow you to do stupid things that, on some compilers and systems, have side effects that appear to be what you want. The languages were designed with the concept of trusting the programmer in most cases, and allowing almost anything to be done.

    This is why when you write code in either of these two languages, you must know exactly what it is that you're writing. You can't base your code only on the fact that something appeared to work properly before.

    Since you didn't tell us what type the variable answer is, I can't tell you how to properly compare it. If it's a C-style string, then while strcmp() would probably be the function to use, you ought to consider using std::string instead. Otherwise, if it is a std::string, you should look up how to compare those.

    Quote Originally Posted by StoryGame464 View Post
    although if u arent going to be helpful and just be critical id prefer if u didnt reply cuz it doesnt help anyone
    Well, you wrote crap and called it C++. What the question was designed to do was make you think. Giving you the benefit of the doubt, you would have believed your code was correct, but only based on incorrect premises. Rethinking your basis for your code might have helped you see the light, as there is little way for us to figure out how you managed to think that code would work. Since we don't know what it is that made you think your code was legit, tabstop asked you to explain your reasoning. This might have helped him have insight into helping you figure out what to do next.

    I do have to say, though, if you aren't one to receive criticism, get out of programming. Programming is not for sensitive people. This forum, while very helpful in the extreme, is all about giving and receiving criticism, helping people to become better at writing programs. If you're going to snap at something mild that tabstop said, you aren't really worth helping. Compared to what he said to you, you're going to get chewed up and spit out by many other members, especially if you're not open to learning.

Popular pages Recent additions subscribe to a feed

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