Num1 = Convert.ToInt32(Console.ReadLine()) Ask the user to type the first number.Ĭonsole.WriteLine("Type a number, and then press Enter") Display title as the C# console calculator app.Ĭonsole.WriteLine("Console Calculator in C#\r") Ĭonsole.WriteLine("-\n") Declare variables and then initialize to zero. In the code editor, replace all the code in program.cs with the following new code: using System When you run the app, the result changes accordingly.Ĭontinue by adding a more complex set of calculator code to your project. For example, you can change the + operator in the int c = a + b line of code to - for subtraction, * for multiplication, or / for division. Optionally, you can change the operator to change the result. To build and run your app, press F5, or select the green arrow next to the name Calculator in the top toolbar.Ī console window opens that shows the sum of 42 + 119, which is 161. The following animation isn't intended to demonstrate the preceding code, but only to show how IntelliSense works.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |