Advertisement
adriyanbulgary

Console Input-Output - Task 5

Jun 14th, 2014
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.54 KB | None | 0 0
  1. using System;
  2. /*
  3.  * Write a program that reads 3 numbers: an integer a (0 ≤ a ≤ 500),
  4.  * a floating-point b and a floating-point c and prints them in 4 virtual
  5.  * columns on the console.Each column should have a width of 10 characters.
  6.  * The number a should be printed in hexadecimal, left aligned;then the number
  7.  * a should be printed in binary form, padded with zeroes, then the number b should be
  8.  * printed with 2 digits after the decimal point, right aligned; the number c
  9.  * should be printed with 3 digits after the decimal point, left aligned.
  10.  */
  11. class FormattingNumbers
  12. {
  13.     static void Main()
  14.     {
  15.         int a= -1;
  16.         while (a < 0 || a > 500) // Check the entered number. The code can be made without this part.
  17.         {
  18.             Console.Write("Enter an intteger number:\n a = ");
  19.             a = int.Parse(Console.ReadLine());
  20.             if (a < 0 || a > 500)
  21.             {
  22.                 Console.WriteLine("The number must be in a range (0;500)");
  23.             }
  24.         }
  25.         Console.Write("Enter some float numbers:\n b = ");
  26.         float b = float.Parse(Console.ReadLine());
  27.         Console.Write(" c = ");
  28.         float c = float.Parse(Console.ReadLine());
  29.  
  30.         //Prints the table
  31.  
  32.         Console.WriteLine("|{0,-10:X}|{1,10}|{2,10:F2}|{3,-10:0.000}|",a,Convert.ToString(a,2).PadLeft(10,'0'), b, c);
  33.        
  34.         //Console.WriteLine("\n|{0,-10}|{1,10}|{2,10:0.##}|{3,-10:0.###}|", a.ToString("X"), Convert.ToString(a, 2).PadLeft(10, '0'), b, c);
  35.      
  36.         Console.Read();
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement