TNJ TNJ - 1 year ago 130
C# Question

Converting decimal to binary with user input

I wanna make a c# application that convert a decimal number into binary with the input from the user. I get a red squiggly line on bin, when declaring bin = Convert.ToString(decToBin,2);. I don't understand my problem, so any help would be appreciated.

int decToBin;
Console.WrinteLine("Enter a number that will be converted to binary")
decToBin = Int32.Parse(Console.Readline());

bin = Convert.ToString(decToBin,2);


Answer Source

i guess you haven't declared bin. it should be

int decToBin;
Console.WriteLine("Enter a number that will be converted to binary");
decToBin = Int32.Parse(Console.ReadLine());
string bin = Convert.ToString(decToBin, 2);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download