Advertisement
g-stoyanov

Exercise8UserChoiceInput

Nov 30th, 2012
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.00 KB | None | 0 0
  1. using System;
  2.  
  3. class Exercise8UserChoiceInput
  4. {
  5.     static void Main()
  6.     {
  7.         int intInput = 0;
  8.         double doubleInput = 0;
  9.         byte typeOfInput = 0;
  10.         Console.Write("Please insert int, bool or string type: ");
  11.         string stringInput = Console.ReadLine();
  12.         if (int.TryParse(stringInput, out intInput))
  13.         {
  14.             typeOfInput = 1;
  15.         }
  16.         else if (double.TryParse(stringInput, out doubleInput))
  17.         {
  18.             typeOfInput = 2;
  19.         }
  20.         Console.WriteLine("\n\n");
  21.         switch (typeOfInput)
  22.         {
  23.             case 1:
  24.                 Console.WriteLine("Your input data type is integer (+1): {0}\n\n", (intInput + 1));
  25.                 break;
  26.             case 2:
  27.                 Console.WriteLine("Your input data type is double (+1): {0}\n\n", (doubleInput + 1));
  28.                 break;
  29.             default:
  30.                 Console.WriteLine("Your input data type is string (+'*'): {0}\n\n", (stringInput + '*'));
  31.                 break;
  32.         }
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement