CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2013
    Posts
    2

    Help solve the question in a language C #?

    The program of conversion
    1. Binary to decimal
    2. Decimal to binary
    3. Hex decimal to decimal
    4. Decimal to hex decimal
    5. Octal to decimal
    6. Decimal to octal

    Means at the user's request, for example, the introduction of No. 4
    Convert from Decimal to hex decimal
    Thus, the rest of the options, preferably without work ARRAYS

  2. #2
    Join Date
    Nov 2013
    Posts
    2

    Re: Help solve the question in a language C #?

    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                string ch;
                while (true)
                {
                    Console.WriteLine("1 . convert from binary to decimal");
                    Console.WriteLine("2 . convert from decimal to binary");
                    Console.WriteLine("3 . convert from Hexdecimal to decimal");
                    Console.WriteLine("4 . convert from decimal to hexdecimal");
                    Console.WriteLine("5 . convert from octal to decimal");
                    Console.WriteLine("6 . convert from decimal to octal");
                    Console.WriteLine("7 . Exit");
                    ch = Console.ReadLine();
                    if (ch == "1")
                    {
                        string binary;
                        Console.WriteLine("Enter the binary number");
                        binary = Console.ReadLine();
                        int power = 1;
                        int number = 0;
                        int counter = 0;
                        for (int i = binary.Length - 1; i <= 0; i--)
                        {
                            if (binary[i] == '1')
                                counter = number + power;
                            power = power * 2;
    
                        }
    
                    }
                    Console.WriteLine("the decimal number is :");
    
    
    
                    if (ch == "2")
                    {
                        int Number;
                        string binary = "";
                        Console.Write("Enter the decimal number ");
                        Number = Int32.Parse(Console.ReadLine());
                        while (Number > 0)
                        {
                            binary = Number % 2 + binary;
                            Number = Number / 2;
    
                        }
    
                        Console.WriteLine("the binary number is :",  binary , Number);
    
                    }
                    else if (ch == "3")
                    {
                        break;
                    }
                }
            }
        }
    }

  3. #3
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Help solve the question in a language C #?

    Is there a question in there somewhere?
    Always use [code][/code] tags when posting code.

  4. #4
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: Help solve the question in a language C #?

    We usually do not do homework, but seeing that you have made a small effort, I'm posting.

    Please, when asking a question, explain the nature of the problem and where the problem lies. Usually the debugger will let you know which line is giving a problem and it will provide an error message. Without this vital information, we cannot help properly.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured