Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3602536
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:45:30+00:00 2026-05-18T20:45:30+00:00

Following situation: I have an array with some constant values, which represent ranges. A

  • 0

Following situation: I have an array with some constant values, which represent ranges.
A range is always between two values in the array, e.g.: 10 – 20 = range1
20-30 = range2 and so on…

const int arr[] = {10, 20, 30, 40, 50, 60};

With a Search function, I search for the number(val) between those ranges in arr[] and return the range index where val was found.
For example: if val = 15 → return value would be 1
if val = 33 → return value would be 3

int Search(const int arr[], int n, int val)
{
    int i = 0;

    while (i < n) {
        if (val > arr[i])
            ++i;
        else
            return i;
    }
    return -1;
}

OK, this works out so far…

Now following problem:
I have some parameters let’s call them x, y, z which are simple integers and they depend on the value of val.
The parameter values for x, y, z I know already before compilation, of course they are different for every range.
How can I now set x, y and z using the range index?
How can I make an array for example with the constant parameter values for x, y, z and set them depending on the returned range index? Or should it be a struct?
How would that look like…?

Thx

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T20:45:31+00:00Added an answer on May 18, 2026 at 8:45 pm

    You could hold the parameters for each range in a struct:

    struct range_parameters {
        int x;
        int y;
        // etc
    }
    

    And keep all these structs in a std::vector:

    std::vector<range_parameters> params;
    

    Adding the data would be done like this:

    range_parameters params_for_range_1;
    params_for_range_1.x = 1;
    params_for_range_1.y = 2;
    
    params[0] = params_for_range_1;
    

    So finally you can access the parameters for range n as params[n-1].

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

let us have a situation in which the following program prints some 10 lines
I have the following situation: I built an Access form with a subform (which
I have the following situation: I have site A, which has it's Mercurial repo,
I got the following situation: I have an application configuration in my database which
I have following situation: I have loged user, standard authentication with DB table $authAdapter
I have the following situation: I have a certain function that runs a loop
I have following situation. A main table and many other tables linked together with
I have the following situation: class A { public: A(int whichFoo); int foo1(); int
I have the following situation: A user will define a certain filter on a
I have the following situation I think would be best to show in sample

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.