Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Simple_Calculator
- {
- class Calc
- {
- public static String num1String;
- public static String num2String;
- public static double num1;
- public static double num2;
- public static String oper;
- public static String response;
- public static void Main (string[] args)
- {
- Console.WriteLine ("Simple Text-Based Calculator by Aaron Murphy");
- Console.Write ("First Number>> ");
- num1String = Console.ReadLine ();
- try {
- num1 = Convert.ToInt32 (num1String);
- } catch(Exception) {
- Console.WriteLine ("You did not enter a number. Restarting...");
- Console.WriteLine ("");
- Main (null);
- }
- Console.WriteLine ("");
- Console.Write ("Second Number>> ");
- num2String = Console.ReadLine ();
- try {
- num2 = Convert.ToInt32 (num2String);
- Console.WriteLine ("");
- } catch(Exception) {
- Console.WriteLine ("You did not enter a number. Restarting...");
- Console.WriteLine ("");
- Main (null);
- }
- Console.Write ("Operator(+, -, *, /, sin, cos, %, log, exp, and tan)>> ");
- oper = Console.ReadLine ();
- Console.WriteLine ("");
- if (oper == "+") {
- Console.WriteLine (num1 + " + " + num2 + " = " + (num1 + num2));
- } else if (oper == "-") {
- Console.WriteLine (num1 + " - " + num2 + " = " + (num1 - num2));
- } else if (oper == "*") {
- Console.WriteLine (num1 + " * " + num2 + " = " + (num1 * num2));
- } else if (oper == "/") {
- Console.WriteLine (num1 + " / " + num2 + " = " + (num1 / num2));
- } else if (oper == "sin") {
- Console.WriteLine ("Sin(" + num1 + ") = " + Math.Sin (num1));
- } else if (oper == "cos") {
- Console.WriteLine ("Cos(" + num1 + ") = " + Math.Cos(num1));
- } else if (oper == "%") {
- } else if (oper == "log") {
- } else if (oper == "exp") {
- } else if (oper == "tan") {
- }
- Console.WriteLine ("");
- Console.Write ("Do you want to perform a new calculation(Y/N)?>> ");
- response = Console.ReadLine ();
- if (response == "Y" || response == "y") { //It works if the user types "Y" or "y".
- Console.WriteLine ("");
- Main (null);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment