Beispiel #1
0
        //METHODS
        public static string CheckNumber(string input, List <int> primeNumbers, int currentHighestPrime, out int updatedCurrentHighestPrime)
        {
            //Here we are making sure that the updatedCurrentHighestPrime per default is the currentHighestPrime. It will only change
            //if it turns out the num we are evaluating is both prime and higher.
            updatedCurrentHighestPrime = currentHighestPrime;

            if (Int32.TryParse(input, out int num))
            {
                if (PrimeEvaluator.CheckIfPrime(num))
                {
                    Message = "Yep, that's a prime number. It's added to the list";
                    primeNumbers.Add(num);
                    if (num > currentHighestPrime)
                    {
                        updatedCurrentHighestPrime = num;
                    }
                }
                else
                {
                    Message = "No, that's not a prime number";
                }
            }
            else
            {
                Message = "Not a valid number";
            }

            return(Message);
        }