| SinaSyndrome (2) | |
|
Hello, I'm new to this website and I am pretty excited to be a part of this community now. I am taking my second course in c++ right now and I have this problem where i need to find a way to ask the user to input a number and that number will be set as the size of the array. I know i'm suppose to implement pointers in some way but i'm having trouble with it. Any tips? void GetInfo(const int* numStudents) { const int *numStudents; int y; cout <<"enter amount of students:" << endl; cin >> y; numStudents = &y; school[*numStudents]; //numStudents = school[]; schoolArrayInput(school, *numStudents); } Here is my code so far. | |
|
|
|
| Callum5042 (126) | |
|
Sounds like you need to use dynamic memory, here a link below. http://www.cplusplus.com/doc/tutorial/dynamic/ Also, I don't see that you have declared any arrays. | |
|
|
|
| AbstractionAnon (517) | |||
Line 4: numStudents has already been declared as an argument. Line 9: Are you trying to declare any array? You need a type and a name. You have only one of the two (not sure which). Also, you can't declare any array with a variable. PLEASE USE CODE TAGS (the <> formatting button). Code tags make it easier to help you. | |||
|
|
|||
| SinaSyndrome (2) | |
|
Thanks for the help. sorry I did not put the entire code up. on line 9. school is the type i made using a structure. it contains 3 variables of type double. I;m going to try to correct the code and see what happens. | |
|
|
|
| Framework (3242) | |||||
This is not possible. An array's length must be constant and known during a declaration context. Some compilers, such as GCC, support non-constant array lengths as an extension, however. To create an array during run-time, you will need to reserve memory from the heap. Here's an example:
See here for further details: http://www.cplusplus.com/doc/tutorial/dynamic/ Wazzak | |||||
|
Last edited on
|
|||||
| helios (10258) | ||
| ||
|
|
||