Hello again, as I said now I show you how to programme in C# a calculator. Make a new file - console applicaciton. We count two numbers, so we need declaration. For declaration we use command int and we name it for example a. It looks like this int a; (don't forget ; on every line!). Make second declaration and name it b, because we count two numbers. It's good to write a message for user e.g. Welcome, enter first number, enter second number - by command console writeline (from previous article). For save number, which user wrote service this command: a=int.Parse(Console.ReadLine()); (then write b). For counting use consolewriteline and into brackets write simply a+b (without " ", it services only for text, not for operations!). Then finish programme using the command consolereadkey. Check syntax errors and run the programme.
Your code should look like this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Calculator
{
class Program
{
static void Main(string[] args)
{
int a;
int b;
Console.WriteLine("Welcome to my calculator, continue always pressing ENTER.");
Console.WriteLine("Write first number.");
a = int.Parse(Console.ReadLine());
Console.WriteLine("Write second number.");
b = int.Parse(Console.ReadLine());
Console.WriteLine("Result is:");
Console.WriteLine(a+b);
Console.ReadKey();
}
}
}
Next lesson I will learn you conditions.
No comments:
Post a Comment