Thread: Code Problem!!

  1. #1
    x4000 Ruski's Avatar
    Join Date
    Jun 2002
    Location
    Outer Space!
    Posts
    542

    Exclamation Code Problem!!

    What's the prolem in my code :

    Code:
    #include <iostream.h>
    #include <stdlib.h>
    #include <windows.h>
        int Tic[3][3];
    void ClearBoard(void)
    {
        Tic[0][0] = 0;
        Tic[0][1] = 0;
        Tic[0][2] = 0;
        Tic[1][0] = 0;
        Tic[1][1] = 0;
        Tic[1][2] = 0;
        Tic[2][0] = 0;
        Tic[2][1] = 0;
        Tic[2][2] = 0;
    }
    void ShowBoard(void)
    {
        cout << Tic[0][0] << Tic[0][1] << Tic[0][2] << endl;
        cout << Tic[1][0] << Tic[1][1] << Tic[1][2] << endl;
        cout << Tic[2][0] << Tic[2][1] << Tic[2][2] << "\n\n\n";
    }
    void StartGame(void)
    {
        char name1[50];
        char name2[50];
        cout << "\n\nStarting A New Game!" << endl;
        cout << "Player1, please input your name: ";
        cin >> name1;
        cout << "Player2, please input your name: ";
        cin >> name2;
        cout << "\nStarting battle: " << name1 << " vs. " << name2 << endl;
        ClearBoard();
        ShowBoard();
        int i;
        i = 0;
        int col;
        int row;
        do
        {
            cout << "Turn: " << name1 << endl;
            cout << name1 << ", please input your move: ";
            cin >> col;
            cin >> row;
            Tic[col-1][row-1] = 1
            ShowBoard();
            cout << "Turn: " << name2 << endl;
            cout << name2 << ", please input your move: ";
            cin >> col;
            cin >> row;
            Tic[col-1][row-1] = 1
            ShowBoard();
        }while(x != 0);
    }
    
    int main()
    {
        cout << "Welcome To Tic Tac Toe !" << endl;
        cout << "Menu:\n\n";
        cout << "1. Start New Tic Tac Toe Game" << endl;
        cout << "2. Exit Tic Tac Toe" << endl << endl;
        cout << "Your choice: ";
        int choice;
        cin << choice;
        switch(choice)
        {
            case 1: StartGame();
                    break;
            case 2: 
                    cout << "Thanks For Playing Tic Tac Toe!" << endl;
                    cout << "Programmed By Dark-Dragon ([email protected])" << endl;
                    system("pause");
                    return 0;
                    break;
            default:
                    cout << "Error Input! Quitting...";
                    system("cls");
                    system("pause");
                    return 0;
        }
    
    }
    Thanks
    what does signature stand for?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    You didn't say what was wrong

    But at a guess, it doesn't compile

    Perhaps
    cin << choice;

    Should be
    cin >> choice;

  3. #3
    x4000 Ruski's Avatar
    Join Date
    Jun 2002
    Location
    Outer Space!
    Posts
    542

    Talking Got It!

    Yup! Thanks I got it!
    what does signature stand for?

  4. #4
    Registered User billholm's Avatar
    Join Date
    Apr 2002
    Posts
    225
    (LOL) Hahaha! What a nice problem Your code works fine except for that "cin << choice;" part. It's amazing how one stupid line can mess up a finely written code... happens to me sometimes too.
    All men are created equal. But some are more equal than others.

    Visit me at http://www.angelfire.com/my/billholm

  5. #5
    x4000 Ruski's Avatar
    Join Date
    Jun 2002
    Location
    Outer Space!
    Posts
    542

    Talking Yea.. LOL

    Yup, that's it. Now, how can you create like windows applications in Dev-C++? I mean i checked out the API but it's too difficult, Isnt Borland Easier? All the controls in the toolbox? Just Drag and Drop?
    Thanks
    what does signature stand for?

  6. #6
    Registered User billholm's Avatar
    Join Date
    Apr 2002
    Posts
    225
    Programming Windows GUI's in C/C++ isn't easy. There's already a de facto standard for Windows API in C++. It isn't the same for all compiler vendors, but they are very similar in methodology.

    PHP Code:
    For Borlandint pascal WinMain(HINSTANCE hInstHINSTANCE
                                                       prev
    LPSTR cmdLineint Show)
                        {
                        }

    For 
    Microsoftint WINAPI WinMain(/*sOMETHING SIMILAR*/)
                          {
                          } 
    I have a hard time soaking up Windows API too
    All men are created equal. But some are more equal than others.

    Visit me at http://www.angelfire.com/my/billholm

  7. #7
    x4000 Ruski's Avatar
    Join Date
    Jun 2002
    Location
    Outer Space!
    Posts
    542
    C++ GUI isnt tough when it comes to using Borland C++ 5.0, Because I had the Enterprise Edition and all you have to do is just drag and drop a control on your form, double click it and write in the code. As simple as that. Why doesnt Dev-C++ have that? Why do i need to use WinApi to create a simple window?
    Thanks
    what does signature stand for?

  8. #8
    Unregistered
    Guest
    try this, slightly more maintainable.

    Code:
    #include <iostream.h>
    #include <stdlib.h>
    #include <windows.h>
    
    const short REELS=3, SYMBOLS=3;
    
    void ClearBoard(int [REELS][SYMBOLS]);
    void ShowBoard(int [REELS][SYMBOLS]);
    void StartGame(int [REELS][SYMBOLS]);
    
    
    int main()
    {
        int Tic[3][3];
    
        cout << "Welcome To Tic Tac Toe !" << endl;
        cout << "Menu:\n\n";
        cout << "1. Start New Tic Tac Toe Game" << endl;
        cout << "2. Exit Tic Tac Toe" << endl << endl;
        cout << "Your choice: ";
        int choice;
        cin >> choice;
        switch(choice)
        {
            case 1: StartGame(Tic);
                    break;
            case 2:
                    cout << "Thanks For Playing Tic Tac Toe!" << endl;
                    cout << "Programmed By Dark-Dragon ([email protected])" << endl;
                    system("pause");
                    break;
            default:
                    cout << "Error Input! Quitting...";
                    system("cls");
                    system("pause");
    
        }
        return 0;
    }
    
    void ClearBoard(int Tic[REELS][SYMBOLS])
    {
      for(int i=0; i < REELS; i++)
        for(int j=0; j < SYMBOLS; j++)
          Tic[i][j]=0;
    }
    void ShowBoard(int Tic[REELS][SYMBOLS])
    {
        cout << Tic[0][0] << Tic[0][1] << Tic[0][2] << endl;
        cout << Tic[1][0] << Tic[1][1] << Tic[1][2] << endl;
        cout << Tic[2][0] << Tic[2][1] << Tic[2][2] << "\n\n\n";
    }
    void StartGame(int Tic[REELS][SYMBOLS])
    {
        char name1[50];
        char name2[50];
        cout << "\n\nStarting A New Game!" << endl;
        cout << "Player1, please input your name: ";
        cin >> name1;
        cout << "Player2, please input your name: ";
        cin >> name2;
        cout << "\nStarting battle: " << name1 << " vs. " << name2 << endl;
        ClearBoard(Tic);
        ShowBoard(Tic);
        int i=0, col, row, x;
        do
        {
            cout << "Turn: " << name1 << endl;
            cout << name1 << ", please input your move: ";
            cin >> col;
            cin >> row;
            Tic[col-1][row-1] = 1;
            ShowBoard(Tic);
            cout << "Turn: " << name2 << endl;
            cout << name2 << ", please input your move: ";
            cin >> col;
            cin >> row;
            Tic[col-1][row-1] = 1;
        }while(x != 0);
    }

  9. #9
    Registered User
    Join Date
    Jan 2002
    Posts
    559
    Originally posted by Ruski
    C++ GUI isnt tough when it comes to using Borland C++ 5.0, Because I had the Enterprise Edition and all you have to do is just drag and drop a control on your form, double click it and write in the code. As simple as that. Why doesnt Dev-C++ have that? Why do i need to use WinApi to create a simple window?
    Thanks
    Haven't used Borland, but your use of the word "form" and drag and drop seems more like Visual Basic, or, coming from Borland, Delphi, not C++. All are used to develop Windows applications, and have some coding similarities, but I've never seen/heard of drag and drop C++ IDEs.
    But, could be wrong.
    VB and Delphi (from the little I know of it, have to learn it for a new job) are both RAD tools to quickly develop apps. C/C++ are generally used for more advanced/bigger apps, and give much more control to the programmer, at the expense of more work for the programmer.
    VB is ultimately based on c/c++ (I think), while Delphi is based on Pascal (I know).
    [Edit]
    Actually, MSVC does have some drag and drop capabilities, I just haven't used them, so maybe Borland does too. There's still lots more coding involved, though. The word "form" does seem like VB or Delphi, though[/Edit]
    Last edited by salvelinus; 06-29-2002 at 09:38 AM.
    Truth is a malleable commodity - Dick Cheney

  10. #10
    x4000 Ruski's Avatar
    Join Date
    Jun 2002
    Location
    Outer Space!
    Posts
    542
    Got it..
    Thanks
    what does signature stand for?

  11. #11
    Registered User
    Join Date
    Mar 2002
    Posts
    125
    Also, when you start a new Windows app, you get a free window in Dev C++! Now you just have to code things in it, and the only way to do that is *GASP* learn the Windows API. I never got around it myself either.
    Typing stuff in Code::Blocks 8.02, compiling stuff with MinGW 3.4.5.

  12. #12
    In The Light
    Join Date
    Oct 2001
    Posts
    598
    howdy,
    i use Borland C++ Builder 5, it IS C++ it however uses OWL instead of MFC. i don't have a great deal of experience with it but i can asure you that the sorce code is real honest to goodness C++.

    M.R.
    I don't like you very much. Please post a lot less.
    Cheez
    *and then*
    No, I know you were joking. My point still stands.

  13. #13
    x4000 Ruski's Avatar
    Join Date
    Jun 2002
    Location
    Outer Space!
    Posts
    542
    Yea, I used the trial verson of Borland C++ Builder and also tought it's good, but when I discovered that it ends in 60 days of use, I just dropped it and Never want to see it again, so I chose Dev-C++. I know that to make the windows, controls, etc you have to use WindowsAPI and I've got a good tutorial website bout that, but it's kinda bit difficult to understand and memorize all that code.. for one simple window ... 50 lines of code that's no fun ... But I asked some people on IRC and they told me that I'll get used to that just like they did, so i think I'll be fine.
    Thanks
    what does signature stand for?

  14. #14
    looking for the truth moemen ahmed's Avatar
    Join Date
    Feb 2002
    Location
    Egypt
    Posts
    161
    visual c++ is a great compiler for doing such things, all u need to make a window(form maybe used) is one click!!!!!! drag and drop abilities r available to establish GUI easilly .
    unforunatly its expensive for many people
    thats the only disadvantage about VC++ as I think, but all of us know its all about microsoft(the money hummy)
    Programming is a high logical enjoyable art for both programer and user !!

  15. #15
    Much older and wiser Fountain's Avatar
    Join Date
    Dec 2001
    Location
    Engeeeerland
    Posts
    1,158
    read my signature-it works fine for me
    Such is life.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Code problem
    By sybariticak47 in forum C++ Programming
    Replies: 9
    Last Post: 02-28-2006, 11:50 AM
  2. Problem with game code.
    By ajdspud in forum C++ Programming
    Replies: 5
    Last Post: 02-14-2006, 06:39 PM
  3. problem with selection code
    By DavidP in forum Game Programming
    Replies: 1
    Last Post: 06-14-2004, 01:05 PM
  4. Replies: 5
    Last Post: 12-03-2003, 05:47 PM
  5. Help with code for simple Y2K problem
    By Mule in forum C++ Programming
    Replies: 3
    Last Post: 03-06-2003, 12:53 AM