473,403 Members | 2,270 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

generating an array of arrays

1
Good day,

I am attempting to generate an array of arrays. The code compiles but hangs when I run it (suggesting an infinite loop perhaps?). I am unsure how code would be necessary for a wise and kind :) person to help me, but I have included what I deemed necessary.

Thank you

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <fstream>
  3. #include <iomanip>
  4. #include <vector>
  5. #include <cmath>
  6. #include <stdio.h>
  7. #include <cstdlib>
  8. #include <ctype.h>
  9.  
  10. using namespace std;
  11.  
  12. int main (){
  13.  
Skip opening and reading in initial data and finding distances between points (sab_array and tab_array).
These sections work correctly.

nsteps and narray are previously entered constants.

Here is where I am trying to generate the array of arrays.

Expand|Select|Wrap|Line Numbers
  1.   vector<double> tsab_array;
  2.   for(int j=0; j<narray;j++)
  3.     {
  4.       for(int i=1; i=nsteps; i++)
  5.     {
  6.     double tsab = (1-1/i)*sab_array[j] - i*(tab_array[j]);
  7.     tsab_array.push_back(tsab);
  8.     }
  9.     }
  10.   for(vector<double>::iterator v=tsab_array.begin(); v != tsab_array.end(); v++)
  11.     {
  12.       cout<<*v<<"\n";
  13.     }
  14.  
  15.   return 0;
  16. }
  17.  
Jul 18 '06 #1
2 3970
D_C
293 100+
In the second for loop, you should be testing i != nsteps instead of assigning i = nsteps.
Jul 18 '06 #2
Banfa
9,065 Expert Mod 8TB
D_C is right also even if you correct that unless you are sure that nsteps >= 1 then you might get what appears to be an infinite loop because it can take a long time to count to 2^32 if you have 32 bit ints.

This is why it is often better not to compare to a single value in a for loop but to compare to the end of a range, i.e. rather than i != nsteps use i < nsteps.

Finally I see no construct in your code that could be interpreted as an array of arrays, tsab_array is just an array of double


This calculation

(1-1/i)*sab_array[j] - i*(tab_array[j])

has a slightly odd effect, for any given j if i ranges between 1 and 4 then I think it will issue the values

-tab_array[j]
sab_array[j] - 2*tab_array[j]
sab_array[j] - 3*tab_array[j]
sab_array[j] - 4*tab_array[j]

is this the output you required?
Jul 19 '06 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
16
by: Leon | last post by:
I need a program that generate 5 non-duplicates random number between 1-10 as string values store in an array. Do anybody know of any good books or websites that explain how to generator random...
21
by: yeti349 | last post by:
Hi, I'm using the following code to retrieve data from an xml file and populate a javascript array. The data is then displayed in html table form. I would like to then be able to sort by each...
104
by: Leszek | last post by:
Hi. Is it possible in javascript to operate on an array without knowing how mamy elements it has? What i want to do is sending an array to a script, and this script should add all values from...
24
by: Michael | last post by:
Hi, I am trying to pass a function an array of strings, but I am having trouble getting the indexing to index the strings rather than the individual characters of one of the strings. I have...
28
by: Nutkin | last post by:
Basicly i have to make a program that calculates the distance between x and y points in 2d space. the code basicly goes like this 1. User says how many points they have (max of 10) 2. User...
57
by: buuuuuum | last post by:
why array can't be assigned, like structs?
17
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hi Gurus, I need to transfer a jagged array of byte by reference to unmanaged function, The unmanaged code should changed the values of the array, and when the unmanaged function returns I need...
1
by: chiefychf | last post by:
I'm working on a school project and I am having a few issues... The program calls for three arrays a,b,c that have to be sorted, then compared to even or odd and stored in arrays d & e, then merge...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.