ARRAY PROBLEM

1
2
3
4
5
6
7
8
9
10
11
12
13
int main(){ 

int card[],number; //MY Question is about this line .

cout<<"Number =";
cin>>number;

for(int a=1;a<=number;a++){ 
card[a]=a; 
cout<<card[a]<<endl;} 

return 0; 
}


I dont know the size of card[] array because user decides it .
what should ı do ?
I need the answer for an other code . So ı cant write "int card[number]" under the cin line.
Last edited on
Use a vector:
http://www.cplusplus.com/reference/vector/vector/
1
2
3
4
5
6
7
 
#include <vector> 
std::vector<int> card; 
for(a=0; a<number; a++)
{  card.push_back (a);
    cout<<card[a]<<endl;
} 


PLEASE USE CODE TAGS (the <> formatting button) when posting code.
http://v2.cplusplus.com/articles/jEywvCM9/
It makes it easier to read your code and it also makes it easier to respond to your post.
Hint: You can edit your previous post, highlight you code and press the <> formatting button.
Last edited on
Topic archived. No new replies allowed.