Like Tree1Likes
  • 1 Post By Elysia

Can someone help with my finished program?

This is a discussion on Can someone help with my finished program? within the C++ Programming forums, part of the General Programming Boards category; So I am working out a problem from Beginning C++ through game programming. I wrote my tic tac toe code ...

  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
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,706
    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,548
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,706
    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をこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,614
    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.
    rags_to_riches likes this.
    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, 01:10 AM
  3. FINISHED - lottery program
    By threahdead in forum C Programming
    Replies: 7
    Last Post: 01-08-2003, 08:28 AM
  4. My Almost finished program
    By davie_scotland in forum C Programming
    Replies: 2
    Last Post: 02-14-2002, 11:58 AM

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