Advertisement
Dianov

Data Types and Variables - More Exercise (01. Data Type Finder)

Aug 7th, 2021
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.48 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace DataTypeFinder
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             bool isntEnd = true;
  14.  
  15.             while (isntEnd)
  16.             {
  17.                 string input = Console.ReadLine();
  18.                 if (input.ToUpper() == "END")
  19.                 {
  20.                     isntEnd = false;
  21.                     break;
  22.                 }
  23.                 int integerType = 0;
  24.                 float floatingPointType = 0;
  25.                 char charType = ' ';
  26.                 bool boolType;
  27.  
  28.                 if (int.TryParse(input, out integerType))
  29.                 {
  30.                     Console.WriteLine($"{input} is integer type");
  31.                 }
  32.                 else if (float.TryParse(input, out floatingPointType))
  33.                 {
  34.                     Console.WriteLine($"{input} is floating point type");
  35.                 }
  36.                 else if (char.TryParse(input, out charType))
  37.                 {
  38.                     Console.WriteLine($"{input} is character type");
  39.                 }
  40.                 else if (bool.TryParse(input, out boolType))
  41.                 {
  42.                     Console.WriteLine($"{input} is boolean type");
  43.                 }
  44.                 else
  45.                 {
  46.                     Console.WriteLine($"{input} is string type");
  47.                 }
  48.             }
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement