Advertisement
sylviapsh

User Choice To Enter Int/Double/String And Do Actions

Dec 28th, 2012
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.37 KB | None | 0 0
  1. using System;
  2. class UserChoiceToEnterIntOrDoubleOrStringAndDoActions
  3. {
  4.   static void Main()
  5.   {
  6.     //Write a program that, depending on the user's choice inputs int, double or string variable. If the variable is integer or double, increases it with 1. If the variable is string, appends "*" at its end. The program must show the value of that variable as a console output. Use switch statement.
  7.  
  8.     Console.Write("Please choose what type of variable you want to enter.\n 1 : Integer\n 2 : Double\n 3 : String\nEnter your choice 1, 2 or 3 here: ");
  9.     byte choice = byte.Parse(Console.ReadLine());
  10.     Console.Write("Please enter your variable:");
  11.     string userinput = Console.ReadLine();
  12.  
  13.     switch (choice)
  14.     {
  15.       case 1:
  16.         {
  17.           int integerVar = int.Parse(userinput);
  18.           integerVar += 1;
  19.           Console.WriteLine("The increased value of your number is: {0}", integerVar);
  20.         }
  21.         break;
  22.       case 2:
  23.         {
  24.           double doubleVar = double.Parse(userinput);
  25.           doubleVar += 1;
  26.           Console.WriteLine("The increased value of your number is: {0}", doubleVar);
  27.         }
  28.         break;
  29.       case 3:
  30.           userinput += "*";
  31.           Console.WriteLine("The new value of your string is: {0}", userinput);
  32.         break;
  33.       default: Console.WriteLine("Wrong input!");
  34.         break;
  35.     }
  36.   }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement