Page 1 of 1

C# Adding 2+ numbers in a console application *beginners*

Posted: Thu Oct 31, 2013 7:12 am
by thekingajew
Just showing how to add 2 numbers together. Alot of you know this but when i started college i struggled to find answers to these kind of codes so i quickly put a small few line code together.

This can be easily modified and improved.

This can be a start towards making a ( - + * / ) calculator

What the code looks like

Image

How the code runs (This can be enhanced to run better)

Image

Get the code here, When using the code remove the comments "//"
Code: Select all
// Basic add 2 numbers together ...

            // Get number 1
            Console.Write("Please enter number 1 ... ");
            int number1 = int.Parse(Console.ReadLine());

            // Get number 2
            Console.WriteLine("please enter number 2 ... ");
            int number2 = int.Parse(Console.ReadLine());

            // Add number 1 and number 2
            int answer = number1 + number2;

            // Print answer to console 
            Console.WriteLine("the answer is: " + answer);

            // keep the console open until a key is pressed
            Console.WriteLine("press a key to continue ... ");
            Console.ReadKey();
If this is of any use please check out my website http://free4later.com/

Re: C# Adding 2+ numbers in a console application *beginners*

Posted: Thu Oct 31, 2013 7:42 pm
by XTechVB
Very basic, but a good start for who wants to learn C#

Re: C# Adding 2+ numbers in a console application *beginners*

Posted: Thu Oct 31, 2013 8:43 pm
by pip
Very good tutorial #thekingajew and i am glad you signed up it is me xpron3xgamer :) .

Re: C# Adding 2+ numbers in a console application *beginners*

Posted: Thu Oct 31, 2013 10:51 pm
by thekingajew
Hi, Thanks for referring me to this site :) Its helped me and i hope i can help others :)
pip wrote:
Very good tutorial #thekingajew and i am glad you signed up it is me xpron3xgamer :) .