Zeosoft console calculator4/12/2023 ![]() ![]() print error if operation is not available Var op = operations.FirstOrDefault(o => o.Operator = opName) try to get the operation based on the name (a, b) => a b is a lamda expression which is shorthand for private double Add(a, b). Note that Func is a so called delegate that can handle methods like variables. Public Operation(string name, string op, Func action) That allows to define it once and use it gernerally. It looks (and is) quite overengineert for such a simple problem - but for real problems it is often a good choice :).įirst, abstract the 4 mathematical operations and it's attributes. 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. V1.I'm an absolute beginner in programming, and Today I decided to put my knowledge to the test and create a basic c# calculator. V3.0 - 22 / 02 / 09 (yay 2 years later, time flies) X3TC: Merroc's Asteroid List (TC 1.4) (more spoilers inside) X3R: Asteroid Sheet *spoiler* (got brutally locked, i hope i dont have to change it!! ) All links should either point to this thread (from now on) or to the old thread. Īs a final note, please do not link directly to the download link or host this file yourself (without explicit approval of myself). Also if you think you've found a bug, please read the faq, see if it might be a feature. Im especially interested in what kind of data (useless for all i care) about the complex you would like to know. įeedback is very much wanted! Ideas, pointers, errors, please: LET ME KNOW. you dont want to accidently remove an important formula. In short, every yellowish cell is something you might want to adjust, anything else, you better stay out of. There's a lot of data in it as well.īe sure to read the FAQ, it explains how you should use it. It calculates the information you want for your complex. So i'll keep it short in this new thread (more info to be found in the old thread though). We all know what it does, well most of you do. If you dont have Excel, or having problems with my sheet, please check this online calculator by em3e3 (linked because im a nice person). Since i had no problems myself (maybe because i already have it) i cant see if this actually helps, but according to TomasArafel who pointed this out to me, it does. If you're having problems running the macro in Excel, it might help to download and install. With Windows Excel Viewer you can only read the file, but not use the macro or edit anything. ![]() I dont know details, but you might have to turn on a few options to get the macro working. With OpenOffice3 you can use this sheet as if it were Excel. Topic for Dave's Factory Complex Calculator: **support dropped
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |