Skip to content

Instantly share code, notes, and snippets.

@NeonixRIT
Last active October 31, 2019 00:01
Show Gist options
  • Save NeonixRIT/ebcbda932d5e84f4423a0a1ef39b197e to your computer and use it in GitHub Desktop.
Save NeonixRIT/ebcbda932d5e84f4423a0a1ef39b197e to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class Program
{
public static string weightUnit;
static void PoundConvert()
{
bool loop = false;
do
{
if (loop)
{
loop = false;
}
Console.WriteLine("Please input pounds!");
string weightInput = Console.ReadLine();
bool success = double.TryParse(weightInput, out _);
if (success)
{
weightUnit = "Pounds";
Console.WriteLine($"{weightInput} is equal to {Math.Round(Convert.ToDouble(weightInput) / 2.20462, 2)} kilograms.");
}
else
{
loop = true;
Console.WriteLine("Put in a valid number you retard");
}
} while (loop);
}
static void KiloConvert()
{
bool loop = false;
do
{
if (loop)
{
loop = false;
}
Console.WriteLine("Please input kilograms!");
string weightInput = Console.ReadLine();
bool success = double.TryParse(weightInput, out _);
if (success)
{
weightUnit = "Kilograms";
Console.WriteLine($"{weightInput} is equal to {Math.Round(Convert.ToDouble(weightInput) * 2.20462, 2)} pounds.");
}
else
{
loop = true;
Console.WriteLine("Put in a valid number you retard");
}
} while (loop);
}
// Check if value entered is a fucking number so retards don't break it
static void Main(string[] args)
{
string[] pounds = { "pounds", "lbs", "pound", "lb" };
string[] kilograms = { "kilograms", "kg", "kilos", "kilo" };
// Arrays for user inputs
bool loop = false;
// Temporary -- Keep loop going for now
do
{
if (loop)
{
Console.WriteLine("Please input a valid response!!!");
}
loop = false;
Console.WriteLine("Would you like to input pounds or kilograms?");
string inputType = Console.ReadLine();
if (pounds.Any(inputType.ToLower().Contains))
{
PoundConvert();
}
else if (kilograms.Any(inputType.ToLower().Contains))
{
KiloConvert();
}
else
{
loop = true;
}
} while (loop);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment