Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.40 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6. using System.Threading;
  7. using System.Threading.Tasks;
  8.  
  9. namespace Test
  10. {
  11.     class Program
  12.     {
  13.         public static Int32 Height;
  14.         public static Int32 Base;
  15.         public static Int32 Result;
  16.  
  17.         public static bool isCalculating;
  18.  
  19.         static void Main()
  20.         {
  21.             string UserInput = ""; //This string will be used for information inputted by a user.
  22.  
  23.             Console.Clear(); //Clears the console.
  24.             Console.WriteLine("Input The Height:"); //Writes in the console.
  25.             UserInput = Console.ReadLine(); //Updates the user input string with what the user put into the console.
  26.             if (Regex.IsMatch(UserInput, @"^[0-9]*$")) //Uses Regex to check if the user input is a number.
  27.             {
  28.                 Height = Convert .ToInt32(UserInput); //Converts the user input into a integer.
  29.                 Console.WriteLine("Input The Base:"); //Writes in the console.
  30.                 UserInput = Console.ReadLine(); //Updates the user input string with what the user put into the console.
  31.                 if (Regex.IsMatch(UserInput, @"^[0-9]*$")) //Uses Regex to check if the user input is a number.
  32.                 {
  33.                     Base = Convert.ToInt32(UserInput); //Converts the user input into a integer.
  34.                     DoMath(); //Goto DoMath.
  35.                 }
  36.                 else
  37.                 {
  38.                     Console.Clear(); //Clears the console.
  39.                     Console.WriteLine("Please enter a number."); //Writes in the console.
  40.                     Thread.Sleep(1000); //Sleeps the current tread.
  41.                     Main(); //Goto Main.
  42.                 }
  43.             }
  44.             else
  45.             {
  46.                 Console.Clear(); //Clears the console.
  47.                 Console.WriteLine("Please enter a number."); //Writes in the console.
  48.                 Thread.Sleep(1000); //Sleeps the current tread.
  49.                 Main(); //Goto Main.
  50.             }
  51.         }
  52.  
  53.         static void DoMath()
  54.         {
  55.             isCalculating = true; //Sets isCalculating to true.
  56.             Thread t = new Thread(Calculating);
  57.             t.Start();
  58.  
  59.             Thread.Sleep(1000); //Sleeps the current tread.
  60.             Result = Height * Base / 2; //Does the maths.
  61.             isCalculating = false; //Sets isCalculating to false.
  62.             Thread.Sleep(100); //Sleeps the current tread.
  63.  
  64.             Console.Clear(); //Clears the console.
  65.             Console.WriteLine("Your result is: " + Result); //Writes in the console.
  66.             Console.ReadLine(); //Waits.
  67.         }
  68.  
  69.         static void Calculating()
  70.         {
  71.             do //Loops while isCalculating is true.
  72.             {
  73.                 Console.WriteLine("Calculating."); //Writes in the console.
  74.                 Thread.Sleep(100); //Sleeps the current tread.
  75.                 Console.Clear(); //Clears the console.
  76.                 Console.WriteLine("Calculating..");
  77.                 Thread.Sleep(100); //Sleeps the current tread.
  78.                 Console.Clear(); //Clears the console.
  79.                 Console.WriteLine("Calculating...");
  80.                 Thread.Sleep(100); //Sleeps the current tread.
  81.                 Console.Clear(); //Clears the console.
  82.             } while (isCalculating is true);
  83.         }
  84.     }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement