![]() ![]() If you are intested in a more object oriented approach, I'll show you an alternative solutions. You solution look fine so far (maybe to much empty lines, but that's just peanuts )). The user is not able to verify the results, since the application immediately terminates after the calculation is evaluated. Console.WriteLine(num1 / num2) // when num2 is 0Īnd nothing happens when an unknown operator is provided by the user.double num2 = Convert.ToDouble(Console.ReadLine()).double num1 = Convert.ToDouble(Console.ReadLine()).The user may also expect this application to crash on: Console.Write("Now, Give me number one: ") Īlso, one time with a comma and capital after it, and one time the other way around: Console.Write("Now give me number two: ") You expect a number, not in a moment, but Now! And you are not asking, you are demanding. You slip up slightly next (forgot a question mark): Console.WriteLine(name " What do you wanna do") īut then you start pressuring the end-user. You're off to a good start: Console.WriteLine("Hi! What is your name?") If you ever wish to design end-user interfaces, you have to work on your lingo. Console.WriteLine("Type ' ' for addition") Ĭonsole.WriteLine("Type '-' for subtraction") Ĭonsole.WriteLine("Type '*' for multiplication") Ĭonsole.WriteLine("Type '/' for division") ![]() Console.WriteLine("Type \" \" for addition") use a switch statement rather than verbose if-elseif.If you Have any suggestions, please give them! using System Ĭonsole.WriteLine("Hi! What is your name?") Ĭonsole.WriteLine(name " What do you wanna do") Ĭonsole.WriteLine("Type \" \" for addition") Ĭonsole.WriteLine("Type \"-\" for subtraction") Ĭonsole.WriteLine("Type \"*\" for multiplication") Ĭonsole.WriteLine("Type \"/\" for division") Ĭonsole.Write("Now, Give me number one: ") ĭouble num1 = Convert.ToDouble(Console.ReadLine()) Ĭonsole.Write("Now give me number two: ") ĭouble num2 = Convert.ToDouble(Console.ReadLine()) I've Done it, but now I'm looking for ways to Make it more shorter and readible. I'm an absolute beginner in programming, and Today I decided to put my knowledge to the test and create a basic c# calculator. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |