Why does my program keeps crashing
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Why does my program keeps crashing

  1. #1
    Join Date
    Apr 2010
    Posts
    26

    Why does my program keeps crashing

    Ok i have an assignment that required me to create a simple database using C++. I tried using both ways which is structures and 2d arrays. But it just keep crashing the command prompt!! Can somebody take a look at the code and tell me the problem? Thank you very much in advance. P.S: I am new to programming. I can hardly understand classes so please be detailed in your explaination.
    ---------------------------------------------------------------
    the structure program
    ------------------------------------------------------------

    #include <iostream>

    using namespace std;


    int add_record()
    {struct weapon
    {int id;
    int name;
    int quantity;
    };

    int i,k,size,l;
    i=1;
    l=0;
    k=1;
    size=0;
    weapon add[size];
    cout<< "Enter size of record"<< endl;
    cin>> size;


    for( l=0; l<size;l++)
    {
    cin>> add[l].id;
    }



    for( l=0; l<size;l++)
    {
    cout<< add[l].id<< endl;
    }

    return 0;
    }
    int main()
    {
    add_record();

    system ("PAUSE");
    return 0;
    }


    =========================================================
    the array prog
    =========================================
    #include <iostream>

    using namespace std;

    int main()
    {int row, a,b;
    b=0;
    const int column=3;
    char weapon [row][column];
    row=1;
    cout<< "Please enter row "<< endl;
    cin>> row ;

    for ( a=0; a<row; a++)
    {b=0;
    for (b=0; b<3; b++)
    { cout << "Enter id, quantity,name" <<endl;
    cin>>weapon[a][b];
    }
    };

    for ( a=0; a<row; a++)
    {b=0;
    for (b=0; b<3; b++)
    {
    cout<< weapon[a][b]<< " ";
    }

    cout<< endl;
    };
    system ("pause");
    return 0;
    }


    _--------------------------------------------------------------------------------

  2. #2
    Join Date
    Apr 2010
    Posts
    26

    Re: Why does my program keeps crashing

    #include <iostream>

    using namespace std;


    int add_record()
    {struct weapon
    {int id;
    int name;
    int quantity;
    };

    int i,k,size,l;
    i=1;
    l=0;
    k=1;
    size=0;
    weapon add[size];
    cout<< "Enter size of record"<< endl;
    cin>> size;


    for( l=0; l<size;l++)
    {
    cin>> add[l].id;
    cin>> add[l].name;
    cin>> add[l].quantity;
    }



    for( l=0; l<size;l++)
    {
    cout<< add[l].id<< endl;
    cout<< add[l].name<< endl;
    cout<< add[l].quantity<< endl;
    }

    return 0;
    }
    int main()
    {
    add_record();

    system ("PAUSE");
    return 0;
    }

    This is the real structure program. I post the wrong thing sorry.

  3. #3
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    5,927

    Re: Why does my program keeps crashing

    Code:
    size=0;
    weapon add[size];
    cout<< "Enter size of record"<< endl;
    cin>> size;
    The size changed later never results in allocating an additional weapon. Your add still remains of zero size.
    Best regards,
    Igor

  4. #4
    Join Date
    Apr 2010
    Posts
    26

    Re: Why does my program keeps crashing

    I see i will try improving it and see the result thank you

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center