开发者

Print index from array

开发者 https://www.devze.com 2023-02-09 15:52 出处:网络
I am working on a text-based game, and I want to print the results in the end. However, at the moment it only prints the latest input data and not the 5 loops 开发者_C百科in the array.

I am working on a text-based game, and I want to print the results in the end. However, at the moment it only prints the latest input data and not the 5 loops 开发者_C百科in the array.

This is my array

int[] turnarr = new int[5];

turnarr[x] = turn;

for (int i = 0; i < turnarr.Length; i++)
     Console.WriteLine(turnarr[i] + "\t" );


It's hard to be certain, as I only see part of the code, but I suspect that you are recreating the turnarr array in each turn, which would make every entry except the last one zero.


If the value of x never changes then you're only writing to a single item in the array, and thus overwriting it every time with the latest value of turn.


If turn is your last turn value, and x is 4, you will see four zeroes on their own lines and then the value of turn because you are only assigning to the xth index of turnarr


I took a look at your pastebin and tracked the issue down I believe:

The following line:

Console.WriteLine(turnarr[i] + "\t" + windarr[i] + " ms \t" + apmeterarr[x] + "m\t\t" + lenghtarr[x] + " meter\t\t");

you are using i for 2 spots, and x for the other 2 for your index variable...

Change apmeterarr[x] and lenghtarr[x]

To apmeterarr[i] and lenghtarr[i]

0

精彩评论

暂无评论...
验证码 换一张
取 消