Thread: Practice Problems Help

  1. #1
    Registered User
    Join Date
    Mar 2014
    Posts
    1

    Practice Problems Help

    I'm reading through "Jumping into C++" and doing the practice problems. After the chapter on switches and enums one of the practice problems is to create a tic tac toe game. I've looked all through the previous chapters but I can't find a way to build a game board with spaces that can be filled with an X or an O. I don't really understand the concept if an enumerate which may be my problem. I'm not asking for the solution, just where to look so that I have the knowledge to solve it myself. Thank you for your help!

  2. #2
    Registered User
    Join Date
    Nov 2013
    Location
    Norway
    Posts
    40
    Enumerated types are basically assigning a value to a "word" and you can use that word later on as a replacement for that value which helps readability. I know what the book wants you to do, and that is to create an enumerated type which contains X and O, and then check whether or not a board position contains either X or O, but the exercise is kinda weird and since it is a book for beginners, the prior chapters and the question doesnt give much information on how the complete program should look like.

    I too had problems with that exercise, and you are gonna find some other exercises weird as well. Some chapters may sound very greek at times (atleast they did to me) and suddenly the type of exercises or the difficulty level completely change.

    I started reading "Jumping into C++", but I switched to "C++ Primer 5th edition" instead. Exercises like the one you mentioned made me switch and the fact that "C++ Primer" is much more detailed and they introduce you to (in my very unprofessional opinion) programming concepts and general programming a lot easier and better. I kinda suggest you to switch to another book as well(I recommend C++ Primer).
    "Derp, derp, derp" - Me

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    C++ Primer which you mention is a very good book. I'd recommend this, as well.

    As for an enumeration, basically it creates a new type and the only "valid" values you can assign to a variable of that type is the ones mentioned inside the enumeration type.
    To give a comparison, consider a ranged integer. Say you want a variable that can only hold numbers from 0 to 100. No other values are valid. Then you would theoretically create a new type where you tell the compiler: limit the valid values to these that I specify.
    An enumeration is the same concept. It allows you to create a new type and tell the compiler that these values are the only valid values this variable can hold.

    So for tic-tac-toe, you would create an enumeration that contains X and O. That tells the compiler that any variable of this enumeration type can only hold these two values. All other values are invalid.
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Where to find practice problems for C
    By ryant324 in forum C Programming
    Replies: 9
    Last Post: 01-31-2014, 08:16 PM
  2. More Chapter 5 practice problems!
    By tsdad in forum C++ Programming
    Replies: 13
    Last Post: 05-17-2013, 11:06 AM
  3. Chapter 2 practice problems
    By Kyle Spalding in forum C++ Programming
    Replies: 14
    Last Post: 03-19-2013, 06:12 AM
  4. Practice Problems
    By Eultza in forum C++ Programming
    Replies: 3
    Last Post: 01-02-2004, 12:13 PM
  5. Practice C Problems, with answers
    By john123 in forum C Programming
    Replies: 3
    Last Post: 12-01-2002, 06:46 PM