Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading;
- using System.Threading.Tasks;
- namespace Test
- {
- class Program
- {
- public static Int32 Height;
- public static Int32 Base;
- public static Int32 Result;
- public static bool isCalculating;
- static void Main()
- {
- string UserInput = ""; //This string will be used for information inputted by a user.
- Console.Clear(); //Clears the console.
- Console.WriteLine("Input The Height:"); //Writes in the console.
- UserInput = Console.ReadLine(); //Updates the user input string with what the user put into the console.
- if (Regex.IsMatch(UserInput, @"^[0-9]*$")) //Uses Regex to check if the user input is a number.
- {
- Height = Convert .ToInt32(UserInput); //Converts the user input into a integer.
- Console.WriteLine("Input The Base:"); //Writes in the console.
- UserInput = Console.ReadLine(); //Updates the user input string with what the user put into the console.
- if (Regex.IsMatch(UserInput, @"^[0-9]*$")) //Uses Regex to check if the user input is a number.
- {
- Base = Convert.ToInt32(UserInput); //Converts the user input into a integer.
- DoMath(); //Goto DoMath.
- }
- else
- {
- Console.Clear(); //Clears the console.
- Console.WriteLine("Please enter a number."); //Writes in the console.
- Thread.Sleep(1000); //Sleeps the current tread.
- Main(); //Goto Main.
- }
- }
- else
- {
- Console.Clear(); //Clears the console.
- Console.WriteLine("Please enter a number."); //Writes in the console.
- Thread.Sleep(1000); //Sleeps the current tread.
- Main(); //Goto Main.
- }
- }
- static void DoMath()
- {
- isCalculating = true; //Sets isCalculating to true.
- Thread t = new Thread(Calculating);
- t.Start();
- Thread.Sleep(1000); //Sleeps the current tread.
- Result = Height * Base / 2; //Does the maths.
- isCalculating = false; //Sets isCalculating to false.
- Thread.Sleep(100); //Sleeps the current tread.
- Console.Clear(); //Clears the console.
- Console.WriteLine("Your result is: " + Result); //Writes in the console.
- Console.ReadLine(); //Waits.
- }
- static void Calculating()
- {
- do //Loops while isCalculating is true.
- {
- Console.WriteLine("Calculating."); //Writes in the console.
- Thread.Sleep(100); //Sleeps the current tread.
- Console.Clear(); //Clears the console.
- Console.WriteLine("Calculating..");
- Thread.Sleep(100); //Sleeps the current tread.
- Console.Clear(); //Clears the console.
- Console.WriteLine("Calculating...");
- Thread.Sleep(100); //Sleeps the current tread.
- Console.Clear(); //Clears the console.
- } while (isCalculating is true);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement