I have a MainScore integer which will only ever be one of the following numbers - 2,4,8,15, 20.

I want to run a test on another integer checkBob (lest say the value is 9) with the following logic. If checkBob is less than 10, increase MainScore by two steps in the number sequence. If checkBob is greater than 10, increase
MainScore by one step in the sequence.

So in this example, if MainScore was originally 4, it would change to 15. (increase by 2 steps in the sequence)

I want to run a test on another integer checkBob (lest say the value is 9) with the following logic. If checkBob is less than 10, increase MainScore by two steps in the number sequence. If checkBob is greater than 10, increase MainScore by one step in the sequence.

Okay, let's walk through the parts here, you need:

Something to store and access values of your sequence (which won't change)

A mechanism to find where your current item is within your sequence.

A function might look something like this:

public static int UpdateStore(int score)
{
// Store your sequence
var sequence = new int[]{ 2, 4, 8, 15, 20 };
// Lookup your current value in the sequence
var currentIndex = sequence.IndexOf(score);
// Determine how much to increment by (2 if less than 10, otherwise 1)
var increment = (score < 10) ? 2 : 1;
// Output the value from the new index
return sequence[currentIndex + increment];
}

One consideration would be, what do you do if you receive 20? Since you wouldn't be able to increase the index by one more?

I want to run a test on another integer checkBob (lest say the value is 9) with the following logic. If checkBob is less than 10, increase MainScore by two steps in the number sequence. If checkBob is greater than 10, increase MainScore by one step in the sequence.

You can try to use
IndexOf method. here a demo for you as a reference.

static void Main(string[] args)
{
List<int> data = new List<int> { 2, 4, 8, 15, 20 };
Console.WriteLine("please write a number");
int number = Convert.ToInt32(Console.ReadLine());
int index = data.IndexOf(number);
if (number > 10)
{
index++;
}
else
{
index = index + 2;
}
Console.WriteLine(data[index]);
Console.ReadKey();
}

Best regards,

Sam

MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

Member

229 Points

681 Posts

## Bit of help with some basic logic

Jan 21, 2020 04:17 PM|RichardLaw|LINK

Hi,

I have a MainScore integer which will only ever be one of the following numbers - 2,4,8,15, 20.

I want to run a test on another integer checkBob (lest say the value is 9) with the following logic. If checkBob is less than 10, increase MainScore by two steps in the number sequence. If checkBob is greater than 10, increase MainScore by one step in the sequence.

So in this example, if MainScore was originally 4, it would change to 15. (increase by 2 steps in the sequence)

How do I write this in C#.net

Many thanks

All-Star

45921 Points

19996 Posts

## Re: Bit of help with some basic logic

Jan 21, 2020 04:35 PM|mgebhard|LINK

Homework?

All-Star

114271 Points

18503 Posts

MVP

## Re: Bit of help with some basic logic

Jan 21, 2020 04:35 PM|Rion Williams|LINK

Okay, let's walk through the parts here, you need:

A function might look something like this:

One consideration would be, what do you do if you receive 20? Since you wouldn't be able to increase the index by one more?

Contributor

2530 Points

1078 Posts

## Re: Bit of help with some basic logic

Jan 22, 2020 03:24 AM|samwu|LINK

Hi RichardLaw,

You can try to use IndexOf method. here a demo for you as a reference.

Best regards,

Sam

Please remember to click "Mark as Answer" the responses that resolved your issue.

If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

Member

229 Points

681 Posts

## Re: Bit of help with some basic logic

Jan 22, 2020 11:40 AM|RichardLaw|LINK

Thank you all so much for your time and support. I went with this option in the end, although I'm sure the others work too.

I did need to change one line to the following to get it to work for me:

Thank you again. As always, very much appreciated.