So I have been learning java this past year in school, but now I am trying to teach myself C++ and I am confused. I want to create an array of any size the user wants. But I cant do it the same way as in java and I want to know why and how can i do it in c++.
int main(){
int numOfCylinders = 1;
cout << "Welcome to the Cylinder Sorter!\n How many cylinders are we creating?\n";
cin >> numOfCylinders;
const int SIZE = numOfCylinders;
Cylinder cylinder[SIZE]; // First i tried making the size of the array equal to numOfCylinders but it
// it said it needed to be a constant value. I then made a const int variable
// called SIZE and assigned its value equal to numOfCylinders hoping that it
// would be a work around to my current issue.
while (true) {
for (int i = 0; i < numOfCylinders; i++) {
cout << "Enter the a character for Cylinder " << i;
cin >> cylinder[i].setName();
}
//rest of code isnt written
}
}
If this doesnt make any sense im sorry...