61
Lemmings Main / Re: Lemmings 2 for Master System
« on: August 16, 2009, 01:27:07 AM »
Where.
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
/*
* Name: ConsoleCalc
* By: Jason Ryfle (zapzupnz)
* Date: 27 07 2009
*
* Description: a simple calculator-like utility for the command line
* written in C# using the .NET libraries and Mono.
*
* License and credits in credits() method.
* Alternatively, run the software and hit the 4 key and press return.
*
* */
using System;
namespace ConsoleCalc
{
class MainClass
{
public static void Main (string[] args)
{
sbyte todoSignedByte = 0;
Console.Clear();
Console.WriteLine("Welcome to ConsoleCalc\nChoose a function from the list below by entering the number.\n\n");
Console.WriteLine("1. Calculation\n2. Area\n3. Powers\n4. Credits\n\n");
try
{
todoSignedByte = sbyte.Parse(Console.ReadLine());
}
catch
{
todoSignedByte = sbyte.Parse(Console.ReadLine());
}
if (todoSignedByte == 0)
{
Console.WriteLine("Terminating...");
return;
}
else if (todoSignedByte == 1)
{
calculator();
}
else if (todoSignedByte == 2)
{
area();
}
else if (todoSignedByte == 3)
{
powers();
}
else if (todoSignedByte == 4)
{
credits();
}
else if (todoSignedByte > 4)
{
Console.WriteLine("Terminating...");
return;
}
}
public static double Evaluate(string expression)
{
System.Data.DataTable table = new System.Data.DataTable();
table.Columns.Add("expression", string.Empty.GetType(), expression);
System.Data.DataRow row = table.NewRow();
table.Rows.Add(row);
return double.Parse((string)row["expression"]);
}
static void calculator()
{
Console.Clear();
Console.WriteLine("Write your calculation:");
try
{
string problemString = Console.ReadLine();
Console.WriteLine("Answer is: " + Evaluate(problemString));
}
catch
{
Console.WriteLine("Invalid formula. Press any key to try again.");
Console.ReadKey();
calculator();
}
}
static void area()
{
Console.Clear();
Console.WriteLine("Choose a shape from the list by number." +
"\n" +
"\n1. Rectangle" +
"\n2. Circle" +
"\n3. Triangle" +
"\n4. Trapezoid" +
"\n5. Square or Rhombus" +
"\n6. Parallelogram" +
"\n\n");
sbyte shapeSignedByte = sbyte.Parse(Console.ReadLine());
if (shapeSignedByte == 0)
{
Console.WriteLine("Terminating...");
return;
}
else if (shapeSignedByte == 1)
{
rect();
}
else if (shapeSignedByte == 2)
{
circle();
}
else if (shapeSignedByte == 3)
{
triangle();
}
else if (shapeSignedByte == 4)
{
trapezoid();
}
else if (shapeSignedByte == 5)
{
rect();
}
else if (shapeSignedByte == 5)
{
rect();
}
}
static void rect()
{
Console.WriteLine("\nHow long is this shape?"); double length = double.Parse(Console.ReadLine());
Console.WriteLine("How wide is this shape?"); double width = double.Parse(Console.ReadLine());
Console.WriteLine("Answer is: " + (length * width));
}
static void circle()
{
Console.WriteLine("\nWhat is the diameter of this circle?"); double diameter = double.Parse(Console.ReadLine());
double radius = diameter / 2;
Console.WriteLine("Radius is: " + radius.ToString());
Console.WriteLine("Answer is: " + (radius * radius * Math.PI));
}
static void triangle()
{
Console.WriteLine("\nWhat is the length of the base?"); double length = double.Parse(Console.ReadLine());
Console.WriteLine("How tall is the triangle?"); double height = double.Parse(Console.ReadLine());
Console.WriteLine("Answer is: " + (length * height / 2));
}
static void trapezoid()
{
Console.WriteLine("\nWhat is the length of the one of the bases?"); double base1 = double.Parse(Console.ReadLine());
Console.WriteLine("What is the length of the other base?"); double base2 = double.Parse(Console.ReadLine());
Console.WriteLine("How tall is the trapezoid?"); double height = double.Parse(Console.ReadLine());
Console.WriteLine("Answer is: " + (height*(base1+base2)/2));
}
static void powers()
{
Console.Clear();
Console.WriteLine("What number shall we multiply?"); double toMult = double.Parse(Console.ReadLine());
Console.WriteLine("To what power shall we do this?"); double powerToMult = double.Parse(Console.ReadLine());
Console.WriteLine("Answer is: " + (Math.Pow(toMult, powerToMult)));
}
static void credits()
{
Console.Clear();
Console.WriteLine("A loose adaptation of Dullstar's calculator, " +
"\nconverted to C# using the .NET libraries" +
"\nDeveloped in MonoDevelop for Mac OS X" +
"\nCompiled with Mono" +
"\nYou are free to share and modify this source code");
}
}
}