Advertisement
Fleshian

Untitled

Nov 14th, 2013
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.62 KB | None | 0 0
  1. using System;
  2.  
  3. // Write a program that, depending on the user’s choice, inputs int, double or string variable.
  4. // If the variable is int or double, the program increases it by 1. If the variable is a string,
  5. // the program appends "*" at the end. Print the result at the console. Use switch statement.
  6.  
  7. namespace Chap_5_Exc_08
  8. {
  9.     class Program
  10.     {
  11.         static void Main()
  12.         {
  13.             Console.WriteLine("Please enter 1 for int 2 for double and 3 for string :");
  14.             int choice = int.Parse(Console.ReadLine());
  15.  
  16.             switch (choice)
  17.             {
  18.                 case 1:
  19.                     Console.WriteLine("Enter a whole number"); break;                  
  20.                 case 2:
  21.                     Console.WriteLine("Enter floating point number"); break;                    
  22.                 case 3:
  23.                     Console.WriteLine("Enter a string"); break;                    
  24.                 default:
  25.                     Console.WriteLine("Ivalid choice"); break;
  26.             }
  27.  
  28.             if (choice == 1)
  29.             {
  30.                 int choiceOne = int.Parse(Console.ReadLine());
  31.                 choiceOne += 1;
  32.                 Console.WriteLine(choiceOne);
  33.             }
  34.             else if (choice == 2)
  35.             {
  36.                 double choiceTwo = double.Parse(Console.ReadLine());
  37.                 choiceTwo += 1;
  38.                 Console.WriteLine(choiceTwo);
  39.             }
  40.             else
  41.             {
  42.                 string choiceThree = Console.ReadLine();
  43.                 Console.WriteLine(choiceThree + "*");
  44.             }
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement