Guest User

Int, Double and String

a guest
Sep 24th, 2015
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.13 KB | None | 0 0
  1. using System;
  2.  
  3. namespace IntDoubleString
  4. {
  5.     class IntDoubleString
  6.     {
  7.         static void Main()
  8.         {
  9.             decimal InputType;
  10.             Console.WriteLine("Please choose a type: \n1 --> int \n2 --> double \n3 --> string: ");
  11.             while (!decimal.TryParse(Console.ReadLine(), out InputType) || (InputType != 1 && InputType != 2 && InputType !=3 ))  // using VAR TYPE Decimal and the OR (input !=#) to make sure that only 1,2 AND 3 are accepted as proper input, otherwise prompts again.
  12.             {
  13.                 Console.WriteLine("Please enter proper integer: ");
  14.             }
  15.             switch ((int)InputType)
  16.             {
  17.                 case 1:
  18.                     int CaseInt;
  19.                     Console.WriteLine("Please enter a integer: ");
  20.                     while (!int.TryParse(Console.ReadLine(), out CaseInt)) //gotta make sure that a proper integer is entered.
  21.                 {
  22.                     Console.WriteLine("Please enter proper integer: ");
  23.                 }
  24.                     Console.WriteLine("{0}", CaseInt+1);
  25.                     break;
  26.  
  27.                 case 2:
  28.                     double CaseDouble;
  29.                     Console.WriteLine("Please enter a double: ");
  30.                     while (!double.TryParse(Console.ReadLine(), out CaseDouble))
  31.                 {
  32.                     Console.WriteLine("Please enter proper double: ");
  33.                 }
  34.                     Console.WriteLine("{0}", CaseDouble+1.00);
  35.                     break;
  36.  
  37.                 case 3:
  38.                     Console.WriteLine("Please enter a string: ");
  39.                     string CaseString = Console.ReadLine();
  40.                     Console.WriteLine("{0}", CaseString+"*"); //because it is a string, i do not know of a way to break somehow the input. even an empty input on String type outputs *.
  41.                     break;
  42.  
  43.                 default: Console.WriteLine("Wrong input"); //not really needed, but just in case if you manage somehow to break the program and manage to escape from all other cases and statements.
  44.                     break;
  45.             }
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment