Advertisement
vlad0

Conditional Statements - User Choice

Dec 4th, 2012
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.54 KB | None | 0 0
  1. using System;
  2.  
  3.     class IntDoubleString
  4.     {
  5.         private static void stringChoice()
  6.         {
  7.             string enteredString;
  8.             Console.Write("Enter string: ");
  9.             enteredString = Console.ReadLine();
  10.             enteredString = enteredString + '*';
  11.  
  12.             Console.WriteLine(enteredString);
  13.  
  14.         }
  15.  
  16.         private static void numberChoice()
  17.         {
  18.             double enteredDouble;
  19.             bool successParse;
  20.             do
  21.             {
  22.                 Console.Write("Enter number: ");
  23.                 successParse = double.TryParse(Console.ReadLine(), out enteredDouble);
  24.                
  25.             } while (!successParse);
  26.             enteredDouble++;
  27.  
  28.             Console.WriteLine(enteredDouble);
  29.  
  30.         }
  31.  
  32.  
  33.         static void Main(string[] args)
  34.         {
  35.             string enteredChoice;
  36.  
  37.             Console.Write("Enter your choice(1-int, 2-double, 3-string): ");
  38.             enteredChoice = Console.ReadLine();
  39.  
  40.            
  41.             switch (enteredChoice)
  42.             {
  43.                 case "1":
  44.                     numberChoice(); //int is part of double so double.TryParse() is OK here :)
  45.                     break;
  46.                 case "2":
  47.                     numberChoice();
  48.                     break;
  49.                 case "3":
  50.                     stringChoice();
  51.                     break;
  52.                 default:
  53.                     Console.WriteLine("Error! Wrong Input!");
  54.                     break;
  55.             }
  56.  
  57.         }
  58.  
  59.        
  60.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement