![]() While (!double.TryParse(tempInput, out parse))Īnd use it like this : double firstNumber = SetNumber("Type you first number : ") ĭouble secondNumber = SetNumber("Type you second number: ") ![]() You also don't need the strings stringFirstNumber stringSecondNumber you can just put this all into a method that will check if the input is in correct format and also return the value something like this : private static double SetNumber(string outputText) ![]() Result = Math.Pow(firstNumber, secondNumber) Ĭonsole.WriteLine("\nResult of " firstNumber " " stringOperation " " secondNumber " = " result ".") įirst of all you are not verifying the input of your program. Do someting depending on the operation choose If (stringOperation = " " || stringOperation = "addition")Įlse if (stringOperation = "-" || stringOperation = "soustraction")Įlse if (stringOperation = "*" || stringOperation = "multiplication")Įlse if (stringOperation = "/" || stringOperation = "division")Įlse if (stringOperation = "^" || stringOperation = "exposant")Įlse if (stringOperation = "%" || stringOperation = "reste") String stringOperation = Console.ReadLine() String stringSecondNumber = Console.ReadLine() ĭouble secondNumber = Convert.ToDouble(stringSecondNumber) Ĭonsole.WriteLine("Enter the operation (addition), - (soustraction), * (multiplication), / (division), ^ (exposant) or % (reste) :") String stringFirstNumber = Console.ReadLine() ĭouble firstNumber = Convert.ToDouble(stringFirstNumber) Ĭonsole.WriteLine("Type you second number :") What do you think of my first program? Is it well-formatted and well-written? using System Ĭonsole.WriteLine("Type you first number :") ’*’ for multiplication, ’/’ for division, and ’%’ for remainder. Allow the user to type in ’ ’ for addition, ’-’ for subtraction, Use a switch statement to handle the different operations in different Going to ask the user to type in two numbers and then type in a math The program that we’ll make is going to be a simple calculator. In one of the chapters, he asks us to make a (really) simple calculator as a console application using the switch statement: I then plan to make video games with Unity 3D after. I'm reading this very good book, C# Player's Guide, to learn C#.
0 Comments
Leave a Reply. |