Skip to content

Instantly share code, notes, and snippets.

@Theoistic
Last active June 9, 2020 20:22
Show Gist options
  • Save Theoistic/3f0eca5a15bd4813285b9a101272bf3e to your computer and use it in GitHub Desktop.
Save Theoistic/3f0eca5a15bd4813285b9a101272bf3e to your computer and use it in GitHub Desktop.
using System;
namespace Data_Projekt_2020_EUX
{
class Program
{
/* public boolean that is accessable from all functions. its good to just throw this outside the scope,
* because it will allow all methods in the future to read what your program is at .. at the moment.*/
public static bool Done = false;
static void Main(string[] args)
{
/* Where we define the main program loop that will go on until we say we are done. */
while (Done == false)
{
Console.WriteLine("CPR number format xxxxxx-xxxx example (270102-1234)");
Console.Write("Input CPR number: ");
string CPR = Console.ReadLine();
string DateOfBirth = CPR.Substring(0, 6);
DateTime dateofbirth = DateTime.ParseExact(DateOfBirth, "ddMMyy", null);
DateTime age = (new DateTime(1, 1, 1) + (DateTime.Now - dateofbirth));
int personsAge = age.Year - 1;
bool male = Convert.ToInt32(CPR.Substring(CPR.Length - 1, 1)) % 2 != 0;
Console.Clear();
Console.WriteLine("Height in centimeters example (173)");
Console.Write("Input Height: ");
double Height = Convert.ToDouble(Console.ReadLine());
Console.Clear();
Console.WriteLine("Weight in kilograms example (42)");
Console.Write("Input Weight: ");
double Weight = Convert.ToDouble(Console.ReadLine());
Console.Clear();
Console.WriteLine("Personal data:");
Console.WriteLine("Age: " + personsAge.ToString());
if (male)
{
Console.WriteLine("Gender: Male");
}
else
{
Console.WriteLine("Gender: Female");
}
Console.WriteLine("Height: " + Height);
Console.WriteLine("Weight: " + Weight);
// add a menu loop state
bool menuLoop = true;
while (menuLoop)
{
Console.WriteLine(string.Empty);
Console.WriteLine("Control Menu:");
Console.WriteLine("[1] Calculate BMI");
Console.WriteLine("[2] Calculate energy needs");
Console.WriteLine("[3] Calculate big mac calories and how many km to run to burn them");
Console.WriteLine("[4] Enter a different set of personal stats");
Console.WriteLine("[5] Exit program");
Console.WriteLine("[#] Input Choise: ");
int userChoise = Convert.ToInt32(Console.ReadLine());
switch (userChoise)
{
case 1: BMICalc(Height, Weight, male, personsAge); break;
case 2: EnergiCalc(Height, Weight, male, personsAge); break;
case 3: BigMacCalc(Height, Weight, male, personsAge); break;
case 4: menuLoop = false; break; // set the menu loop state to false so we start from scratch
case 5:
{
menuLoop = false;
Done = true;
} break;
default: Console.WriteLine("You're too drunk to calculate shitz."); break;
}
}
}
}
private static void BigMacCalc(double Height, double Weight, bool male, int age)
{
Console.Clear();
Console.WriteLine("Personal data:");
Console.WriteLine("Age: " + age.ToString());
if (male)
{
Console.WriteLine("Gender: Male");
}
else
{
Console.WriteLine("Gender: Female");
}
Console.WriteLine("Height: " + Height);
Console.WriteLine("Weight: " + Weight);
Console.WriteLine(string.Empty);
Console.Write("How many big mac's would you like to burn?: ");
double BigMacAmount = Convert.ToDouble(Console.ReadLine());
int CaloriesPer = 503;
double TotalCalories = BigMacAmount * CaloriesPer;
double AmountToRun = TotalCalories / Weight;
Console.WriteLine(string.Empty);
Console.WriteLine("You have to run " + AmountToRun + "km");
ExitOption();
}
private static void EnergiCalc(double Height, double Weight, bool male, int age)
{
Console.Clear();
Console.WriteLine("Personal data:");
Console.WriteLine("Age: " + age.ToString());
if (male)
{
Console.WriteLine("Gender: Male");
}
else
{
Console.WriteLine("Gender: Female");
}
Console.WriteLine("Height: " + Height);
Console.WriteLine("Weight: " + Weight);
Console.WriteLine(string.Empty);
double energy = 0.0;
if (male)
{
energy = ((Weight * 42.0) + (Height * 26.3) - (age * 20.7) - 676.2) / 4.2;
Console.WriteLine("You need " + energy + " kcal per day");
}
else
{
energy = ((Weight * 42.0) + (Height * 26.3) - (age * 20.7) + 21) / 4.2;
Console.WriteLine("You need " + energy + " kcal per day");
}
ExitOption();
}
private static void BMICalc(double Height, double Weight, bool male, int age)
{
Console.Clear();
Console.WriteLine("Personal data:");
Console.WriteLine("Age: " + age.ToString());
if (male)
{
Console.WriteLine("Gender: Male");
}
else
{
Console.WriteLine("Gender: Female");
}
Console.WriteLine("Height: " + Height);
Console.WriteLine("Weight: " + Weight);
Console.WriteLine(string.Empty);
double Height2 = Height * Height;
double BMI = Weight / Height2;
double BMIResult = BMI * 10000;
Console.WriteLine("BMI: " + BMIResult);
ExitOption(); // here it is called as an example
}
/* a small helper function, so you dont have to write the same douplicate code in every function ..*/
private static void ExitOption()
{
Console.WriteLine("Wanna exit or try again??");
string option = Console.ReadLine();
if(option.ToLower() == "n")
{
Environment.Exit(1);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment