TheBulgarianWolf

Data Types

Nov 2nd, 2020
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.08 KB | None | 0 0
  1. using System;
  2.  
  3. namespace MoreMethodExercises
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             Console.Write("Enter the type of the input: ");
  10.             string type = Console.ReadLine();
  11.             if (type.Equals("int"))
  12.             {
  13.                 int num = int.Parse(Console.ReadLine());
  14.                 intMethod(num);
  15.             }
  16.             else if (type.Equals("real"))
  17.             {
  18.                 double num = double.Parse(Console.ReadLine());
  19.                 realMethod(num);
  20.             }
  21.             else if (type.Equals("string"))
  22.             {
  23.                 string word = Console.ReadLine();
  24.                 stringMethod(word);
  25.             }
  26.         }
  27.  
  28.         static void intMethod(int number)
  29.         {
  30.             Console.WriteLine(number * 2);
  31.         }
  32.  
  33.         static void realMethod(double number)
  34.         {
  35.             Console.WriteLine("{0:F2}",number*1.5);
  36.         }
  37.  
  38.         static void stringMethod(string word)
  39.         {
  40.             Console.WriteLine("$" + word + "$");
  41.         }
  42.     }
  43. }
  44.  
Add Comment
Please, Sign In to add comment