Thread: I get errors, but not from compiling

  1. #1
    Unregistered Leeman_s's Avatar
    Join Date
    Oct 2001
    Posts
    753

    I get errors, but not from compiling

    I run this and then after started, it says, blah.exe has encountered an error and needs to close. This is a windows message. There are no errors or warning when I compile it. heres the code:

    #include "iostream.h"
    #include "conio.h"
    #include "time.h"
    #include "windows.h"

    void ShowBoard(int Board[][6]);
    void BoardSetup(int Board[][6]);
    void MoveBlockDown(int Board[][6]);

    int main()
    {
    int GameBoard[9][6];
    BoardSetup(GameBoard);
    ShowBoard(GameBoard);
    MoveBlockDown(GameBoard);

    return 0;
    }
    // **************************************************
    void ShowBoard(int Board[][6])
    {
    for(int i=1;i<=8;i++)
    {
    for(int p=1;p<=6;p++)
    {
    cout<<Board[i][p];
    }
    cout<<endl;
    }
    }
    // **************************************************
    void BoardSetup(int Board[][6])
    {
    for(int i=1;i<=8;i++)
    {
    for(int p=1;p<=6;p++)
    {
    Board[i][p]=0;
    }
    cout<<endl;
    }
    for(i=1;i<=6;i++)
    Board[9][i]=2;
    }
    // **************************************************
    void MoveBlockDown(int Board[][6])
    {
    int temp;
    temp=Board[1][3];
    for(int i;i<=9;i++)
    {
    Board[i][3]=9;
    Board[i-1][3]=temp;
    Sleep(1);
    ShowBoard(Board);
    }
    ShowBoard(Board);
    }

  2. #2
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    Your board is defined as: int GameBoard[9][6]; But in function MoveBlockDown you're doing: for (int i; i<=9; i++). Note that it should be "int i = 0;". So when i is 9, then Board[i][3]=9; goes wrong. Since Board[9][3] implies that you're board has size 10, but it only has size 9.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. global namespace errors
    By stubaan in forum C++ Programming
    Replies: 9
    Last Post: 04-02-2008, 03:11 PM
  2. Replies: 4
    Last Post: 03-10-2008, 07:03 AM
  3. Quincy 2005: Compiling Errors
    By Thileepan_Bala in forum C Programming
    Replies: 6
    Last Post: 01-18-2008, 08:26 PM
  4. Replies: 2
    Last Post: 12-07-2004, 02:31 AM
  5. errors in my class....
    By o0obruceleeo0o in forum C++ Programming
    Replies: 9
    Last Post: 04-14-2003, 03:22 AM