Exception crashes here:

B [(int) buff] = B [(int) buff] +1

Actually the code itself:

 void __fastcall TForm1::Button3Click(TObject *Sender) { long m= 356896; long r=95,k=256,b=64,n,f; int buff,i,x; buff=0; double ri = 0; int B[10]; n=StrToInt(Edit1->Text); float A[100]; for (int i=0; i<100; i++) { ri=double((k*r+b)% m); r=ri; ri=ri/m; A[i]=ri; for(int i=0; i<100; i++) { Memo3->Lines->Add(A[i]); buff=A[i]*10+1; Memo4->Lines->Add((int)buff); *******B[(int)buff]=B[(int)buff]+1;******* } for (int i=0; i<10; i++) { Series3->AddXY(i,B[i]/100); } Series4->AddXY(i,(double)random(n)/n); } } 
  • "when compiling" ?? - Igor
  • well, then I made a mistake when compiling, and when I clicked on the button - Credo
  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky ♦

1 answer 1

Well, you don’t initialize the B array at all. The same garbage with A - in the first cycle you barely have time to initialize the first element, just as in the second you use the entire array. I have a suspicion that a nested loop (with the same index!) Is not exactly what you wanted.

And since A not initialized, then anything can be in it. So, in the buff too, anything - that is, going beyond the B array (by the way, why do you bring the int buff to the same int ?) you are guaranteed ...

  • int buff bring int to highlight the whole part - Credo
  • @Credo Whole part of what ?! From a whole number ?? - Harry
  • it’s written in my assignment that it was possible to do this, I didn’t even think about int sticking, well, actually here int B [(int) buff] = B [(int) buff] +1 is unnecessary, it is needed only during initialization buff . - Credo