»
 

Go Back   ResellerRatings Store Ratings > ResellerRatings Forums > Tech Support

Reply
 
LinkBack Thread Tools Display Modes
Old 11-09-2003, 08:42 PM   #1 (permalink)
Registered User
 
Join Date: Sep 2002
Posts: 30
Lambo is on a distinguished road
Loading a double subscripted array

Hey all, who are interested in my question.

Does anyone know how to load a double subscipted array from user input from a keyboard.

for example:

double sales[5][6];

while (condition is != sentinel value)
{
cin >> product >> value;


statement that adds values to the sales array.



I'm only primarily concernd with the "value" input.

How do you add the "value" variable to
the two-dim array without intializing it to the variable "value"?

Any help here would be much appreciated.

I know that there are plenty of gurus out there. So let me hear from ya and thanks.

Lambo is offline   Reply With Quote
Old 11-29-2003, 01:38 AM   #2 (permalink)
Registered User
 
squeech's Avatar
 
Join Date: May 2002
Location: Rocky Mountain High
Posts: 522
squeech is on a distinguished road
If I understand the question fully (and I'd like to think that I am ), you are asking for the best way to fill a 2-D array?

The simplest way is probably just with two for loops and a cin statement...for example:

Code:
double sales[5][6];

for (int i=0;i<5;i++)
{
    for(int j=0;j<6;j++)
        cin >> sales[i][j];
}
The array would look something like this (with indices instead of values) for a 5x6 2-D after declaration:

[0][0] [0][1] [0][2] [0][3] [0][4] [0][5]
[1][0] [1][1] [1][2] [1][3] [1][4] [1][5]
[2][0] [2][1] [2][2] [2][3] [2][4] [2][5]
[3][0] [3][1] [3][2] [3][3] [3][4] [3][5]
[4][0] [4][1] [4][2] [4][3] [4][4] [4][5]


This code fills the array, with values from the keyboard, across the first row until the last column is reached ([0][0],[0][1],[0][2],etc. 'till [0][5]) and then jumps down to the next column and repeats.

Hope this helps!! Let me know if I missed the point entirely and can give better assistance!
__________________
Talking in numbers doesn't make you smarter.
squeech is offline   Reply With Quote
Old 11-29-2003, 11:08 AM   #3 (permalink)
Registered User
 
Join Date: Sep 2002
Posts: 30
Lambo is on a distinguished road
Hey thanks for the reply,

Yeah I figured that I could use that. The real problem was I didn't understand the problem well enough.

After tinkering around with it, I figured it out.

Thanks again for the reply
Lambo is offline   Reply With Quote
Reply




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Most Active Discussions

Recent Discussions

All times are GMT -6. The time now is 02:46 PM.