![]() The result will be 8 hours 30 minutes (8:30 hours or 8.5 hours in decimal) or 510 minutes. For example, how many hours are there between 9 and 5:30 pm (or 9:00 and 17:30)? You simply need to enter the two times in any order and click on "Calculate". ![]() This calculator for the number of hours between two times could be used to find out for how long you have worked in order to fill in timesheets. For example, entering a start time of 6PM and end time of 8AM in the calculator, it will calculate the difference in hours, minutes, and seconds from 6PM today to 8AM tomorrow (14 hours). ![]() If the first hour you enter is later in the day than the second hour you enter, the time difference is calculated as if the first hour is for today and the second is tomorrow. Below you will get the difference in both full hours and in minutes. US, UK.Īfter you enter the beginning and the end of the time period you are interested in, you simply click the "Calculate difference" button. The hours calculator will use the time format depending on your browser locale settings, e.g. To calculate the hours and minutes contained in a time period you need to know its beginning and end. This simple online tool makes it easy to calculate the difference in hours and minutes between two given times. Number of hours in different time periods.Working hours with lunch break excluded.") Ĭonsole.WriteLine($"This operation is not supported. You could then "map" each enum to a function taking two double values and returning another - that's a Func: var strategies = new Dictionary> Say you had an enum: public enum CalculatorOperation How about you take the concern of creating the menu out of there, find a way to encapsulate each operation into its own strategy object, and generate the menu based on how many available strategies you have? It looks like at one point it was intended to support 4 - Multiply, but the idea was dropped and now 4 is an invalid input despite the instructions at the top saying (1-4), and the instructions at the bottom saying 1-3! I'd actually make that function return a double? (or Nullable, so that the calculator knows the number isn't valid when that function returns a null). Your code is making the assumption that the user will enter a valid double! Look into TryParse, and write a separate function with the sole purpose of turning a string into a double. What happens if you play the QA engineer here? Console.WriteLine ("What is your first number?: ") Your code works when the sky is blue and the user isn't being too clever. The first concern you have, is getting user input. So I'm not going to suggest other ways, instead I'm going to hint at how you could improve the flexibility of what you've got. There are as many ways to write a calculator as there are programmers willing to write one. I'll blame the extra-weird broken indentation on copy/paste difficulties, and ignore that. Num02 = double.Parse(Console.ReadLine()) Ĭonsole.WriteLine("\nTotal of " num01 " - " num02 " = " (num01 - num02)) Ĭonsole.WriteLine("Division Selected: ") Ĭonsole.WriteLine("\n Total of " num01 " / " num02 " = " (num01 / num02)) Ĭonsole.WriteLine("Sorry, incorrect input") Num02 = double.Parse (Console.ReadLine()) Ĭonsole.WriteLine ("\nTotal of " num01 " " num02 " = " (num01 num02)) Ĭonsole.WriteLine ("Subtract Selected: ") ![]() UserChoice = int.Parse (Console.ReadLine ()) Ĭonsole.WriteLine ("\nAddition Selected: ") Num01 = double.Parse (Console.ReadLine()) Ĭonsole.WriteLine ("\nPlease select one of the following (1-4)") I'm pretty new to C# and was just wondering if there is a better way I can write this calculator that I made: using System Ĭonsole.WriteLine ("What is your first number?: ")
0 Comments
Leave a Reply. |