1
Answer

Getting a specific nummber from an Array based on variable?

Mazetar

Mazetar

13y
1.6k
1
I have an Array of nummbers like this:
int[] baseSavingThrows = {2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12};

and I have a:

int level;

what I want to do is to be able to get a # from the array based on the level.
I tried using 2d arrays as well as single arrays but I havent been able to figure out how to do this.

I know I can use
Console.WriteLine("Your saving Throw is: {0}", baseSavingThrows);
to display the line: Your saving Throw is: 2

but I can't figure out a way to modify it so it changes with the level variable.
I plan to later use the baseSavingThrows to get the base number and then use it in my calculations, to calculate inn different modifiers and get a totalSaveBonus and then compare that number against another number and then do an action based on that.

The problem is that I can't find a way to extract the correct nummber based on the level variable, so I know I'm doing somthing really wrong and I'm wondering if anyone here has any pointers? 

Answers (1)