can somebody please tell me what is wrong with the code in my c sharp program?

Marc G

New member
using System;
using System.Collections.Generic;
using System.Text;

namespace TestConsole
{
class BinaryToDecimal
{
static void Main(string[] args)
{


int iTotal;
int iNumber1;
int iNumber2;
int iNumber3;



Console.WriteLine("Please enter number 1:");
iNumber1 = Convert.ToInt32(Console.ReadLine());

while (iNumber1 <= 9 && iNumber1 >= 2)
{
Console.WriteLine("The number must be a 1 or a 0, please re enter: ");
iNumber1 = Convert.ToInt32(Console.ReadLine());
}

Console.WriteLine("Please enter number 2:");
iNumber2 = Convert.ToInt32(Console.ReadLine());

while (iNumber2 <= 9 && iNumber2 >= 2)
{
Console.WriteLine("The number must be a 1 or a 0, please re enter: ");
iNumber2 = Convert.ToInt32(Console.ReadLine());
}

Console.WriteLine("Please enter number 3:");
iNumber3 = Convert.ToInt32(Console.ReadLine());

while (iNumber3 <= 9 && iNumber3 >= 2)
{
Console.WriteLine("The number must be a 1 or a 0, please re enter: ");
iNumber3 = Convert.ToInt32(Console.ReadLine());
}


if (iNumber1 == 1)
{
iTotal = iNumber1 + 1;
};

if (iNumber2 == 1)
{
iTotal = iNumber2 + 2;
};

if (iNumber3 == 1)
{
iTotal = iNumber3 + 4;
};

Console.WriteLine("The number you have entered is: " + iNumber1 + iNumber2 + iNumber3 + "The decimal equivalent is " + iNumber1 + iNumber2 + iNumber3 + iTotal);
Console.ReadLine();






}
}
}

ok, the error is always itotal is unassigned and its on the bottom line
and what im trying to do is to get the number you enter, which would be a binary number, and to convert that into a decimal so he would enter 111 and that would equal 7 or something
 
Back
Top