Advertisement
VyaraG

PlayWithIntDoubleAndString

Nov 30th, 2014
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.42 KB | None | 0 0
  1. using System;
  2.  
  3. //Write a program that, depending on the user’s choice, inputs an int, double or string variable. If the variable is int or double, the program increases it by one. If the variable is a string, the program appends "*" at the end. Print the result at the console. Use switch statement. Example:
  4.  
  5.     class PlayWithIntDoubleAndString
  6.     {
  7.         static void Main()
  8.         {
  9.             Console.WriteLine("Please, choose a type:\n1 __> int\n2__>double\n3__>string ");
  10.             string type = Console.ReadLine();
  11.            
  12.             switch (type)
  13.             {
  14.                 case "1":
  15.                     Console.Write("Please, enter an integer: ");
  16.                     int inputInt = int.Parse(Console.ReadLine());
  17.                     Console.WriteLine((inputInt + 1));
  18.                     break;
  19.                 case "2":
  20.                     Console.Write("Please enter a double: ");
  21.                     double doubleInput = double.Parse(Console.ReadLine());
  22.                     Console.WriteLine((doubleInput+1.00));
  23.                     break;
  24.                 case "3":
  25.                     Console.Write("Please, enter a string: ");
  26.                     string stringInput = Console.ReadLine();
  27.                     Console.WriteLine(stringInput+"*");
  28.                     break;
  29.  
  30.                 default: Console.WriteLine("Invalid input!");
  31.                     break;
  32.             }
  33.         }
  34.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement