iNET Interactive - Online Advertising Agency
          
   Home    Authors    About    Login    Contact Us
   Search:   
Advanced Search     
  Articles

  ASP (26)
  ASP.NET (19)
  C and C++ (4)
  CFML (2)
  CGI and Perl (16)
  Flash (2)
  Java (7)
  JavaScript (28)
  PHP (92)
  MySQL (13)
  MSSQL (3)
  HTML (34)
  SEO (9)
  Visual Basic (12)
  CSS (13)
  SSI (5)
  XML (12)
  C# (14)

  Developer News

Courtesy of moreover.com
 
Want to receive new articles via e-mail? Click here!
/Home /C#

Simple Calculator in C# (c sharp) 

  Views:    11169
  Votes:    5
by Adil Saeed Khan 5/14/05 Rating: 

Synopsis:

This article describes how to make simple calculator in C# ( C sharp )
Pages: 
The Article

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|

Pages: 
Attachments:
Simple Calculator in C#.htm [2937 byte] (this html file)



 
  Sponsors