The Swedish word "avgränsare" translates to "delimiter" in English. Use English names for variables, especially when characters outside the range of A-Z, a-z, 0-9, _ are included (such as "ä"). For this C calculator program example, we used the Switch case to check which operand is inserted by the user. Using those two values and operand, it will perform Arithmetic Operations. ) Console.WriteLine ( ' ENTER YOUR FIRST NUMBER:- ' ) firstNumber Convert.ToInt32 (Console.ReadLine ()) Console.WriteLine ( 'ENTER YOUR SECOND NUMBER:- ' ) secondNumber Convert.ToInt32 (Console.ReadLine ()) Console.WriteLine ( ' ENTER YOUR CHOICE ( 1 - 4):- ' ) //get user input choice Convert.ToInt32 (Console. One of the exercises in my book asked me to write a basic console calculator that takes 2 numbers and an operation as input. Overagain: string avgränsare = is enough, you don't need else. This calculator program in C helps the user to enter the Operator (+, -,, or /) and two values. enter the numbers this way: Example(4 + 3)") Ĭonsole.WriteLine("!Use space between numbers!") using System Ĭonsole.WriteLine("This is a calculator. I know my code is messy, and I have probably done many things wrong here, so I would really appreciate every word of advice I can get. Then I want to compare the string operands and the string operator, to see if it is +, -, * or / in the end I have put an if statement, so that if a = null, then the while loop breaks and the result is printed. b = 4 and gets + 2 every time the loop executes. Then I declared a variable called operands which is a. How to use: Help R: Read expression E: Evaluate and print latest expression E n: Evaluate and print nth expression P: Print latest expression postfix P n: Print nth expression postfix I: Print latest expression infix I n: Print nth expression infix T: Print latest. The calculator evaluates a mathematical expression with binary operators +, -,, / and in C. i is 3 and gets + 2 every time the while loop executes. Then I am using the string.Split to know whether it's an operator or a number.Īfter that I have used a while loop if a.Length is over 2 and if it is, I declared an double numbers which is a. I have variables firstnumber and secondnumber, as well as operand and result.
0 Comments
Leave a Reply. |