Help: Text-Based Roulette Game

This is a discussion on Help: Text-Based Roulette Game within the C++ Programming forums, part of the General Programming Boards category; manutd - Thanks for that bit of code on indenting...thats kinda what I was looking for. What other ways are ...

  1. #16
    Registered User
    Join Date
    Nov 2006
    Posts
    13

    Smile

    manutd - Thanks for that bit of code on indenting...thats kinda what I was looking for. What other ways are there to indent? Anyone know of a link to some advice on that? Thanks for the input everyone!

  2. #17
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    Another way (somewhat different):
    Code:
    for (int i = 0; i <= 10; i++){
         if (i %2 == 0){
              cout << "It's even!" << endl;
         }
         else{
              cout << "It's odd!" << endl;
         }
    }
    And another:
    Code:
    for (int i = 0; i <= 10; i++)
    {
         if (i %2 == 0)
              cout << "It's even!" << endl;
         else
              cout << "It's odd!" << endl;
    }
    Check out this site.
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  3. #18
    Registered User
    Join Date
    Nov 2006
    Posts
    13
    I'll run it through my compiler when I get home I'm at school. What is wrong with the cout statements?

  4. #19
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    You say something like this:
    Code:
    cout << "new - New game 
      << endl
      "exit - Exit game
      << endl << endl;
    This won't compile. MinGW gives this:
    8 C:\Dev-Cpp\cprog\main.cpp missing terminating " character
    9 C:\Dev-Cpp\cprog\main.cpp expected primary-expression before '<<' token
    10 C:\Dev-Cpp\cprog\main.cpp missing terminating " character
    This will compile, but not what you want:
    Code:
    cout << "new - New game << endl exit - Exit game << endl << endl";
    This outputs:
    new - New game << endl exit - Exit game << endl << endl
    What you want:
    Code:
    cout << "new - New Game" << endl << "exit - Exit game" << endl << endl;
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  5. #20
    Registered User
    Join Date
    Jan 2005
    Posts
    7,344
    Code:
    cout << "new - New Game\nexit - Exit game\n\n";
    might be even more appropriate. All of the endl's are unnecessary. IMO adding newlines into the output string is clearer.

  6. #21
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    Yes, but I was just trying to preserve his original code.
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  7. #22
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,479
    Instead of endl new line '\n' works equally as well.

    @manutd I approve of your indent sytle, for me its three spaces to every indent. I hate tabs, they annoy me. I only use tabs if I really have to. But manual indentation sticks in your brain more than hitting tab. Of course it all depends on how the OP's IDE is set up
    I'm just trying to be a better person - My Name Is Earl

  8. #23
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,581
    > Instead of endl new line '\n' works equally as well.

    I agree. However let it be said that, endl may be useful for debugging purposes. Along with ends or flush, it flushes the buffer. When using cout for debugging purposes, if the application crashes the buffers will not be flushed and this may give the wrong impression on where the program crashed.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  9. #24
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    @swgh: I just set the settings to make a tab 5 spaces (I know, it's wierd) and then use tabs.
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  10. #25
    Registered User
    Join Date
    Nov 2006
    Posts
    13

    Talking

    That help on that code was cool! I was so tired adding that in I wasn't thinking and never closed the quotes lol. As for new line... we went over stuff like '/n' and '/t' etc, but I just used endl since I was more comfortable with that as a low-level programmer. I'll try to do better with my syntax...I know it must hurt seeing my code. Anything else you all could think of that I should keep in mind is all great. I take advice very well actually.

  11. #26
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    One thing (maybe a typo on your part, I do this often): '/n' != '\n'.
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  12. #27
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,479
    >I know it must hurt seeing my code.

    Dont put yourself down like that. Everybody has to start somwhere. We all make mistakes, and asking when you re unsure is one of the best ways to learn, especialy in programming
    I'm just trying to be a better person - My Name Is Earl

  13. #28
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,581
    Well... that looooong code... it did hurt
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  14. #29
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    But honestly, compared to some, this is awesome You've learned from this, and you made a try before coming to us. Continue learning and you'll do well with C++.
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  15. #30
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,479
    >Well... that looooong code... it did hurt

    Tut tut mario.... its a work in progress..
    I'm just trying to be a better person - My Name Is Earl

Page 2 of 3 FirstFirst 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Text based game
    By wipeout4wh in forum C Programming
    Replies: 12
    Last Post: 03-26-2009, 05:39 PM
  2. text based mmo type game.....
    By SONAR in forum Game Programming
    Replies: 0
    Last Post: 12-09-2008, 05:17 AM
  3. Text based game
    By beene in forum Game Programming
    Replies: 10
    Last Post: 05-12-2008, 08:52 PM
  4. easiest way to make text based game?
    By oceanrats in forum C++ Programming
    Replies: 7
    Last Post: 08-13-2005, 03:17 PM
  5. Saving a text game
    By Unregistered in forum C++ Programming
    Replies: 4
    Last Post: 03-27-2002, 01:33 PM

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