Thread: Can someone help with my finished program?

  1. #1
    Registered User
    Join Date
    Jul 2012
    Posts
    3

    Can someone help with my finished program?

    So I am working out a problem from Beginning C++ through game programming. I wrote my tic tac toe code with global variables and now I am trying to rewrite it without them. However, when I try to pass them through ass arguments from main I get all heaps of problems. Here is my code with globals:

    I got it fixed !
    Last edited by Doom123; 07-28-2012 at 01:44 PM.

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Well, to be honest I'm not finding much wrong here. It would be a different story if the game board or such were a global variable. Named constants don't really present the same problems as global variables do.

  3. #3
    Registered User
    Join Date
    Jul 2012
    Posts
    3
    Quote Originally Posted by whiteflags View Post
    Well, to be honest I'm not finding much wrong here. It would be a different story if the game board or such were a global variable. Named constants don't really present the same problems as global variables do.
    I'm sorry I meant to say that this code works 100% fine, but I am trying to remove lines 1-6 and that is what I am having problems with doing. It was easy to write this with those variables but sticking them in main and parsing them through as arguments is where I get a lot of problems.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    C++ Index values in Fif Game
    C++ Index Values - C++ Forum
    Yes there is a lot of renaming, but 12 functions in a row achieving the same "purpose" on a like-for-like basis.

    I'm wondering how much original effort is in this code.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    I'm sorry I meant to say that this code works 100% fine, but I am trying to remove lines 1-6 and that is what I am having problems with doing.
    I understood correctly. In my opinion, there is no reason to refine the scope of those constants. As I said, named constants do not present the same problems that global variables do. If you insist on changing it, then you will have to pass the constants around as arguments, and the parameters of the functions also have to be constant. Again, it would buy you nothing in my opinion.

  6. #6
    Registered User
    Join Date
    Jul 2012
    Posts
    3
    Salem, this is a problem in the book I mentioned by Michael Dawson, he provides a tutorial on this problem.

    Whiteflags, oh okay thank you!

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Please don't remove your code when you find a solution. Instead, share your solution.
    This forum is just as much as about helping you as helping others, and they can benefit from your problem and your solution.
    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. Program almost finished
    By alex1067 in forum C Programming
    Replies: 3
    Last Post: 04-05-2008, 10:03 PM
  2. I have finished my program, one problem
    By sloopy in forum C Programming
    Replies: 4
    Last Post: 11-29-2005, 02:10 AM
  3. FINISHED - lottery program
    By threahdead in forum C Programming
    Replies: 7
    Last Post: 01-08-2003, 09:28 AM
  4. My Almost finished program
    By davie_scotland in forum C Programming
    Replies: 2
    Last Post: 02-14-2002, 12:58 PM