Hello , i am making an interchange program that switch the values of two variables . For example :
Input: Output:
nr1 = 2 nr1 = 3
nr2 = 3 nr2 = 2
This is my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Programc : Numbers
{
public static void Main(string[] args)
{
Numbers numbers = new Numbers();
numbers.GetNr1();
numbers.GetNr2();
numbers.InternGhange();
}
}
class Numbers
{
public int nr1;
public int nr2;
public int temp;
public void GetNr1()
{
Console.WriteLine("Read nr1:");
nr1 = Console.Read();
Console.ReadLine();
}
public void GetNr2()
{
Console.WriteLine("Read nr2:");
nr2 = Console.Read();
Console.ReadLine();
}
public void InternGhange()
{
temp = nr1;
nr1 = nr2;
nr2 = temp;
Console.WriteLine("The numbers are now:");
Console.ReadLine();
Console.WriteLine("nr1={0}",nr1);
Console.ReadLine();
Console.WriteLine("nr2={0}",nr2);
}
}
}
But if at input nr1=2 and nr2=3 at the output nr1=50 and nr2=51
Where is the problem.Please help me to find out.I will appreciate your help.