int size = busNodes.size(); double * distancearray=new double[size]; for(int value = 0;value<busNodes.size();value++) { distancearray[value]=Infinity; } 

During the first launch of the program, the number of bus stops is 234, but then I want to change and see how the program considers everything.

The problem is only in one, when creating an array, it does not create 234 stops with an infinity distance, but creates only one.

What am I doing wrong? And there were already many topics on this topic, only doing everything as described in those topics and not only here, I still get one stop.

Closed due to the fact that off-topic participants Vlad from Moscow , Abyx , pavel , cheops , Denis 25 Oct '16 at 6:33 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • “Questions asking for help with debugging (“ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - Abyx, pavel, cheops, Denis
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • Loop by value , and some unknown i . - αλεχολυτ
  • @alexolut yes, thanks for the comment, but everything in the program is correct, it was wrong here .. The point is not in this error, the essence is different - Misha Ostapchuk
  • is that busNodes.size () returns 1? - Grundy
  • one
    @Grundy At a minimum, I set break points and see what he does with the array. Well, here it is important what you see and how you look, in some debuggers, for example, when viewing the pointer - only the first element is shown - Grundy
  • one
    That's what I think. for the first time busNodes.size() == 10 , then this indicator is reset and becomes 1 (I don’t know how, but this seems to be) the question: why not use the ready-made variable size in the loop? output to output what size and busNodes.size() are equal to - Senior Pomidor

1 answer 1

You did not try to immediately after this make a debugging output?

 cout << "busNodes.size() = " << busNodes.size() << endl; for(int value = 0; value < busNodes.size(); value++) { cout << "distancearray[" << value << "] = " << distancearray[value] << endl; } 

? Most likely, you will have either the wrong busNodes.size() value, or you will find out that something is happening outside this code, or - that you misinterpret what is happening ...

Exotic type

 #define Infinity 0; break 

not considered :)