C# is no doubt very simple and powerful language. Here is a code of simple calculator which I made in C#. You can see its syntax is very similar to C and C++.
Here's the code :
|
using System;
public class Calculator { public static void Main() { int num1; int num2; string operand; float answer;
Console.Write("Please enter the first integer: "); num1 = Convert.ToInt32(Console.ReadLine());
Console.Write("Please enter an operand (+, -, /, *): "); operand = Console.ReadLine();
Console.Write("Please enter the second integer: "); num2 = Convert.ToInt32(Console.ReadLine());
switch (operand) { case "-": answer = num1 - num2; break; case "+": answer = num1 + num2; break; case "/": answer = num1 / num2; break; case "*": answer = num1 * num2; break; default: answer = 0; break; }
Console.WriteLine(num1.ToString() + " " + operand + " " + num2.ToString() + " = " + answer.ToString());
Console.ReadLine();
} } |
Suggestions and comments are welcomed.
By : Adil Saeed Khan
Url : www.adilsaeed.com
e-mail : iam@adilsaeed.com
Phone : |+92-300-5283757|