473,419 Members | 1,790 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,419 software developers and data experts.

How to make an array without setting the size first?

I want to create an array to store values from user input. The user input is in a while (choice=='y' || choice=='Y') loop. As long as the user keeps selecting Y/y at the end of the loop, they can enter more values and continue. I want to store the 2 values that are entered and a 3rd calculated value in an array. The user can stop after 1 value or keep going up to 100 iterations of the loop (if they so desire).

My original thought was to create 3 array variables but I am stuck trying to figure out the exact code needed to allow an array(s) to just grow, as needed. I do not want to preset the size of the array to any single value though. Any help in this manner would be appreciated.
Oct 11 '10 #1
3 2593
Dheeraj Joshi
1,123 Expert 1GB
You can use some collection frameworks for this.

Regards
Dheeraj Joshi
Oct 12 '10 #2
Nepomuk
3,112 Expert 2GB
What you're doing sounds a lot like an ArrayList or a Vector, both of which are collections.

Greetings,
Nepomuk
Oct 13 '10 #3
Oralloy
988 Expert 512MB
I'd stick with the ArrayList, unless you require synchronization. But - I suspect that you aren't at the point of needing to know the difference in your training.

Work with what you've got, write a prototype, and if you have any questions about your code - ask them.
Oct 13 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: Christopher Benson-Manica | last post by:
From FAQ 6.13: int arr; int (*a)=arr; /* legal, but useless */ printf( "%d\n", a ); /* error, bounds of a unspecified */ Are there non-contrived situations where an array of unspecified...
3
by: Tee | last post by:
Hi, Anyone know how to redeclare an array with different size but keep the previous data? Just like the redim preserve in VB. Thanks.
8
by: redefined.horizons | last post by:
I would like to have an array declaration where the size of the array is dependent on a variable. Something like this: /* Store the desired size of the array in a variable named "array_size". */...
6
by: foreverbored75 | last post by:
Hello All! I am just learning c++ in school and I have the following question: Is there a way for the user to input the length of an array (console application) without using another variable?...
13
by: hn.ft.pris | last post by:
Hi: I have the following simple program: #include<iostream> using namespace std; int main(int argc, char* argv){ const double L = 1.234; const int T = static_cast<const int>(L); int arr;
5
by: Netaro | last post by:
Hello! So, i have this type of a problem -> i have wrote a function that sorts the array in ascending order. the beggining looks like this -> template <typename T> void...
3
by: quiz123 | last post by:
Hi folks, I have a problem. my function call is void Rotate_n(int array, int arraySize,int n); //precondition: arraysize>=1 && n>=0 && n<=arraySize //post condition: Values in the arrary are...
15
by: subramanian100in | last post by:
Is it possible to measure the size of an array without using the sizeof operator ?
2
by: Pavan | last post by:
Hi, I need to create a consant array of larze size but however its elements can be calculated using an equation, say for example I need an int arry of 20 elements where each element will be arr...
8
by: Sunny | last post by:
Hi, Can someone tell me, How to redefine array or make array empty or null. Here what I am trying to do. var temp = new Array(); for(i=0; i <=outstring.length-1; i++) { temp =...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.