Advertisement
Teodor92

Input

Oct 30th, 2012
853
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.10 KB | None | 0 0
  1. /* Write a program that, depending on the user's choice
  2.  * inputs int, double or string variable. If the variable
  3.  * is integer or double, increases it with 1. If the variable
  4.  * is string, appends "*" at its end. The program must show the
  5.  * value of that variable as a console output. Use switch statement.
  6.  */
  7.  
  8. using System;
  9.  
  10. class ChoiceForInput
  11. {
  12.     static void Main()
  13.     {
  14.         Console.WriteLine("Enter 1 for int, 2 for double, and 3 for string");
  15.         sbyte choice = sbyte.Parse(Console.ReadLine());
  16.         switch (choice)
  17.         {
  18.             case 1: int firstCohise = int.Parse(Console.ReadLine());
  19.                 Console.WriteLine(firstCohise + 1);
  20.                 break;
  21.             case 2: double secondCohise = double.Parse(Console.ReadLine());
  22.                 Console.WriteLine(secondCohise + 1);
  23.                 break;
  24.             case 3: string thirdCohise = Console.ReadLine();
  25.                 Console.WriteLine(thirdCohise + "*");
  26.                 break;
  27.             default: Console.WriteLine("Problem, problem");
  28.                 break;
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement