Advertisement
AnitaN

05.ConditionalStatementsHomework/09.PlayIntDoubleString

Mar 29th, 2014
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.46 KB | None | 0 0
  1. //Problem 9.    Play with Int, Double and String
  2. //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.
  3.  
  4. using System;
  5.  
  6. class PlayIntDoubleString
  7. {
  8.     static void Main()
  9.     {
  10.         Console.WriteLine("Please, choose a type:");
  11.         Console.WriteLine("1--> int");
  12.         Console.WriteLine("2--> double");
  13.         Console.WriteLine("3--> string");
  14.         Console.Write("choose:");
  15.         int choice = int.Parse(Console.ReadLine());
  16.         switch (choice)
  17.         {
  18.             case 1:
  19.                 Console.Write("Please, enter integer number:");
  20.                 int number = int.Parse(Console.ReadLine());
  21.                 Console.WriteLine(number+1);
  22.                 break;
  23.             case 2:
  24.                 Console.Write("Please,enter a double:");
  25.                 double doubleNumber = double.Parse(Console.ReadLine());
  26.                 Console.WriteLine(doubleNumber+1);
  27.                 break;
  28.             case 3:
  29.                 Console.Write("Please, enter a string:");
  30.                 string myString = Console.ReadLine();
  31.                 Console.WriteLine(myString + "*");
  32.                 break;
  33.             default:
  34.                 Console.WriteLine("Some , Error");
  35.                 break;
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement