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

  • Home
  • SEARCH
  • 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 8965739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:52:31+00:00 2026-06-15T16:52:31+00:00

Using a 2D array for the first time for my university project. im struggling

  • 0

Using a 2D array for the first time for my university project.

im struggling on how to place a user entered value into a specific slot in the array.

what i do have is.

cout << "Enter Number of Groups" << endl;
cin >> DefinedGroups;

int user_groups[definedgroups] [2]

while (havent worked out the condition yet)
{
cout << " Enter Lower Range " << endl;
cin >> Lrange;
cout << " Enter Higher Range " << endl;
cin >> Hrange;
}

Anyone Know how I can enter the value from Lrange and Hrange into the array at like 0,1 and 1,1 and then increment the definedgroup by 1 each time. Thanks

  • 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-06-15T16:52:32+00:00Added an answer on June 15, 2026 at 4:52 pm

    Firstly, your code uses Variable Length Arrays which are a GCC extension. This means your code is not portable.

    Now to read into the elements in the array, you could simply do:

    cout << " Enter Lower Range " << endl;
    cin >> user_groups[i][0];
    cout << " Enter Higher Range " << endl;
    cin >> user_groups[i][1];
    

    Assuming that i is an index into the array that you’ll get when you figure out the while loop condition.

    If you’d like to enlighten yourself, you could use a more idiomatic method:

    int defined_groups;
    std::cin >> defined_groups;
    std::vector<std::pair<int, int>> user_groups;
    for (int i = 0; i < defined_groups; i++) {
      int lower_range, upper_range;
      if (cout << "Enter Lower Range " << endl &&
          std::cin >> lower_range &&
          cout << " Enter Higher Range " << endl &&
          std::cin >> upper_range) {
        user_groups.push_back(std::make_pair(lower_range, upper_range));
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my first time using a 3 dimensional array and I am having
I'm using a 2D Array in Java and it's the first time doing so.
This is the first time I'm using this website, I have recently started working
this is my first time using the ListView and have have tried out many
First time trying to find something in an array using an array as both
I'm using Ajax via jQuery for the first time ever. I have an html
This is my first time using stackoverflow for a question, I have read a
Is there anyways to get first two element of each profile_id using php array(
I'm using PostgreSQL 9.1.13 Here is what I've done so far: /* First Array
I am sorting and sectioning a tableview using the first letter of an array

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.