Created
November 8, 2010 20:42
-
-
Save snicol/668223 to your computer and use it in GitHub Desktop.
A C# calculator.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
namespace Calculator | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Start: // this starts from the function, so we can loop back up | |
Console.WriteLine("What function would you like? +, -, x? "); | |
string function = Console.ReadLine(); | |
bool isDone = false; | |
while (isDone == false) | |
{ | |
if (function == "+") | |
{ | |
Console.WriteLine("First digit: "); | |
string first = Console.ReadLine(); | |
int first_convert; | |
Int32.TryParse(first, out first_convert); | |
Console.WriteLine("Second digit: "); | |
string second = Console.ReadLine(); | |
int second_convert; | |
Int32.TryParse(second, out second_convert); | |
int result; | |
result = first_convert + second_convert; | |
Console.Write("Result is {0} \n", result); | |
isDone = true; | |
goto Start; | |
} | |
if (function == "-") | |
{ | |
Console.WriteLine("First digit: "); | |
string first = Console.ReadLine(); | |
int first_convert; | |
Int32.TryParse(first, out first_convert); | |
Console.WriteLine("Second digit: "); | |
string second = Console.ReadLine(); | |
int second_convert; | |
Int32.TryParse(second, out second_convert); | |
int result; | |
result = first_convert - second_convert; | |
Console.Write("Result is {0} \n", result); | |
isDone = true; | |
goto Start; | |
} | |
if (function == "x") | |
{ | |
Console.WriteLine("First digit: "); | |
string first = Console.ReadLine(); | |
int first_convert; | |
Int32.TryParse(first, out first_convert); | |
Console.WriteLine("Second digit: "); | |
string second = Console.ReadLine(); | |
int second_convert; | |
Int32.TryParse(second, out second_convert); | |
int result; | |
result = first_convert * second_convert; | |
Console.Write("Result is {0} \n", result); | |
isDone = true; | |
goto Start; | |
} | |
if (function == "scott") | |
{ | |
Console.WriteLine("SCOTT IS A LEGEND!"); | |
goto Start; | |
} | |
if (function != "+" || function != "-" || function != "x"){ | |
Console.WriteLine("Invalid function given."); | |
goto Start; | |
} | |
} // finishes while loop | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment