diff --git a/Src/BootCamp.Chapter/Checks.cs b/Src/BootCamp.Chapter/Checks.cs index 49864932a..6f67129f1 100644 --- a/Src/BootCamp.Chapter/Checks.cs +++ b/Src/BootCamp.Chapter/Checks.cs @@ -17,25 +17,32 @@ public static class Checks public static int PromptInt(string message) { // To do: call your implementation. - return 0; + + + return Lesson3.PromtInt(message); } public static string PromptString(string message) { // To do: call your implementation. - return ""; + + + return Lesson3.PromtString(message); } public static float PromptFloat(string message) { // To do: call your implementation. - return 0; + + + return Lesson3.PromtFloat(message); } public static float CalculateBmi(float weight, float height) { // To do: call your implementation. - return 0; + + return Lesson3.CalculatingBMI(weight, height); } } } diff --git a/Src/BootCamp.Chapter/Lesson3.cs b/Src/BootCamp.Chapter/Lesson3.cs new file mode 100644 index 000000000..6fb3eadab --- /dev/null +++ b/Src/BootCamp.Chapter/Lesson3.cs @@ -0,0 +1,115 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Xml.Linq; + +namespace BootCamp.Chapter +{ + internal class Lesson3 + { + public static void Demo() + { + string name, surname; + int age; + float weight, height; + int counter = 0; + while (counter < 3) + { + Console.WriteLine("Enter Name:"); + name = Convert.ToString(Console.ReadLine()); + + Console.WriteLine("Enter SurName:"); + surname = Convert.ToString(Console.ReadLine()); + + Console.WriteLine("Enter age:"); + age = int.Parse(Console.ReadLine()); + + Console.WriteLine("Enter weight:"); + weight = float.Parse(Console.ReadLine()); + + Console.WriteLine("Enter height:"); + height = float.Parse(Console.ReadLine()); + + + + Console.WriteLine("{0} {1} is {2} years old his weight is {3} kg and his height is {4} cm.", name, surname, age, weight, height); + + float bmi = (weight / height / height) * 10000f; + Console.WriteLine("your BMI: {0} ", bmi); + + + + + counter++; + } + } + + public static float CalculatingBMI(float weight, float height) + { + if (weight <= 0 || height <= 0) + { + Console.WriteLine("Failed calculating BMI. Reason:"); + + if (height <= 0) + { + Console.WriteLine($"Height cannot be equal or less than zero, but was {height}."); + } + if (weight <= 0) + { + Console.WriteLine($"Weight cannot be equal or less than zero, but was {weight}."); + } + + return -1; + + } + float bmi = (weight / height / height); + return bmi; + } + + public static int PromtInt(string msg) + { + Console.WriteLine(msg); + string input = Console.ReadLine(); + + bool isNum = int.TryParse(input, out int num); + + if (!isNum) + { + Console.WriteLine($"\"{input}\" is not a valid number."); + + return -1; + } + return num; + } + + public static float PromtFloat(string msg) + { + Console.WriteLine(msg); + string input = Console.ReadLine(); + + bool isNum = float.TryParse(input, out float num); + + if (!isNum) + { + Console.WriteLine($"\"{input}\" is not a valid number."); + return -1; + } + return num; + } + public static string PromtString(string msg) + { + Console.WriteLine(msg); + string input = Console.ReadLine(); + + if (String.IsNullOrEmpty(input)) + { + Console.WriteLine("Name cannot be empty."); + return "-"; + } + return input; + } + + + + } +} diff --git a/Src/BootCamp.Chapter/Program.cs b/Src/BootCamp.Chapter/Program.cs index 94e5531bc..788d254c3 100644 --- a/Src/BootCamp.Chapter/Program.cs +++ b/Src/BootCamp.Chapter/Program.cs @@ -9,6 +9,7 @@ class Program { static void Main(string[] args) { + Lesson3.Demo(); } } } diff --git a/docs/images/Failed-Tests.png b/docs/images/Failed-Tests.png new file mode 100644 index 000000000..36d0a2019 Binary files /dev/null and b/docs/images/Failed-Tests.png differ diff --git a/docs/images/TestsWindow.PNG b/docs/images/TestsWindow.PNG new file mode 100644 index 000000000..a9e9efb5f Binary files /dev/null and b/docs/images/TestsWindow.PNG differ