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

Recommended Answers

All 3 Replies

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.