Jamie Dalley

Jamie Dalley

  • NA
  • 16
  • 5.5k

What is wrong with this method / method call?

Jan 30 2013 7:09 AM
Basically i need to make a method that switches the value of two numbers. For some reason at the moment when my program gets to this part it comes up with an error saying input string was not in a correct format. Below i have pasted the bit of the code with the method and the call, any help would be great, thanks in advance:
 int originalNumber;
            int switchNumber;
           

            Console.WriteLine("Enter a number");
            originalNumber = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine("You entered {0}, please enter a second number for it to be switched with", originalNumber);
            switchNumber = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine("The first number is {0} and the second is {1}, press any key to switch them", originalNumber, switchNumber);
            Console.ReadKey();

            SwapNumbers(originalNumber, switchNumber);

            Console.WriteLine("The first number is now {0} and the second is now {1)", originalNumber, switchNumber);

            Console.WriteLine("Press any key to end program");
            Console.ReadKey();


        }
        public static void SwapNumbers(int firstNumber, int secondNumber)
        {
            int temp = 0;
            temp = firstNumber;
            firstNumber = secondNumber;
            secondNumber = temp;          
        }

Answers (6)