0

Hello,

I work on a problem and I want my solution to be picked from discrete numbers.( I want a value for diameter and I want it to be selected from the available diameter values)

Does anyone know it can be done with C++ and how?

Thanks

4
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by MosaicFuneral
0

I'm not sure if I understand the question correctly, but if you want a bunch of numbers which you can choose from, you could use vectors.
Example:

vector<int> diameters;
    /* load a few bogus values */
    diameters.push_back(1);
    diameters.push_back(5);
    diameters.push_back(7);
    /*display available numbers */
    cout << "numbers available: ";
    for (unsigned int i = 0; i < diameters.size(); i++)
        cout << diameters[i] << " ";

output: numbers available: 1 5 7

0

If you have a finite number of values and they aren't going to change, you can get away with using a standard array instead of a vector.

This is only if you have a static amount of values and performance is an issue. If performance doesn't matter, use a vector as suggested from niek_e since you get the perks of a dynamic array as well as information about its size and the ability to use STL algorithms with it to manipulate, copy or iterate through its contents... etc.

-Alex

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.