program.exe has stopped working

Why doesn't this program work?
Whenever I run it windows gives an error message and it shuts down

#include <iostream>

using namespace std;


//store the entered values in an array
int storeseq(int k)
{
int i=0;
int seq[k];


while (i<k)
{
cin>> seq[i];
i=i+1;
}

}

//display the array
int displayseq(int seq[], int k)
{
int i=0;

while (i<k)
{
cout << seq[i];
i=i+1;
}

}

int main ()
{
int k;

int seq[k];
//k is the amount of numbers in the sequence


cout<<"enter k"<<endl;
cin >>k;




storeseq(k);
displayseq(seq, k);


return 0;
}
Last edited on
What error message? Please be specific.

Line 10, 38: You can not allocate an array this way. Array size must be known at compile time. It can not be a variable.

Line 10: This instance of seq is local to storeseq(). It goes out of scope when storeseq exits.

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
Last edited on
Like this error message (but in swedish and "program.exe"):

http://thewindowsclub.thewindowsclubco.netdna-cdn.com/wp-content/uploads/2010/12/14-600x302.png?bbdc8f

Is it possible to keep the value of seq[]?

thanks for the quick answer :)
Last edited on
Topic archived. No new replies allowed.