This post contains a total of 32+ Hand-Picked C Sharp calculator examples. The calculators are made purely using C sharp Programming language.
You can use the source codes of these C Sharp Calculators for educational use with credits to the original owner, if you want it for some other purpose then contact the owner for permission.
Related Posts
Click a Code to Copy it, and Hover over a video to play it.
1. By VEDANG
Made by VEDANG. Input two numbers in first and second line to get the results. The program will give the result of calculation of the two numbers using basic operators. ( Source )
using @System;
using @XPL;
namespace @XPL
{
class @Text
{
public static void @Set(string x)
{
Console.WriteLine(x);
}
public static string @Get()
{
return Console.ReadLine();
}
public static double @ToDouble(object x)
{
return Convert.ToDouble(x);
}
}
}
namespace @Code
{
class @Program
{
static void @Main(string[] args)
{
Text.Set("Enter two numbers : ");
var x = Text.Get();
var y = Text.Get();
try
{
double a = Text.ToDouble (x);
double b = Text.ToDouble(y);
Text.Set("\nSum : " + (a + b));
Text.Set("Difference : " + (a - b));
Text.Set("Product : " + (a * b));
Text.Set("Quotient : " + (a / b));
Text.Set("Remainder : " + (a % b));
Text.Set("Exponent : " + Math.Pow(a, b));
}
catch (FormatException)
{
Text.Set("Invalid Input");
}
Text.Get();
}
}
}
2. By Misarie
Basic calculator by Misarie. You have to first enter the first number then the operator symbol that you want to use, after that the second number. ( Source )
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Calculator
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine ("===========");
Console.WriteLine ("Calculator");
Console.WriteLine ("Operators: +, -, *, /, %.");
Console.WriteLine ("ver 0.0.5");
Console.WriteLine ("by Misarie");
Console.WriteLine ("===========");
Console.Write("1 number > ");
double a = Convert.ToDouble(Console.ReadLine());
Console.Write("operator > ");
string Operator = Console.ReadLine();
Console.Write("2 number > ");
double b = Convert.ToDouble(Console.ReadLine());
if (Operator == "-")
{
Console.Write("Result > ");
Console.WriteLine(a - b);
}
if (Operator == "+")
{
Console.Write("Result > ");
Console.WriteLine(a + b);
}
if (Operator == "*")
{
Console.Write("Result > ");
Console.WriteLine(a * b);
}
if (Operator == "/")
{
Console.Write("Result > ");
Console.WriteLine(a / b);
}
if (Operator == "%")
{
Console.Write("Result > ");
Console.WriteLine(a % b);
}
else
{
Console.WriteLine("result > error");
}
}
}
}
3. By Programming_C#
Made by Programming_C#. You have to enter first number then the operator after that the second number to get the result. ( Source )
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SoloLearn
{
class Program
{
static void Main(string[] args)
{
double num1;
string op;
double num2;
Console.WriteLine("Enter first number");
num1 = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Enter operator" );
op = Console.ReadLine ();
Console.WriteLine("Enter second number");
num2 = Convert.ToDouble(Console.ReadLine());
if(op =="+")
{
Console.WriteLine(num1 + num2);
}else if (op == "-"){
Console.WriteLine(num1 - num2);
}else if (op == "*"){
Console.WriteLine(num1 * num2);
}else if (op == "/"){
Console.WriteLine(num1 / num2);
}else{
Console.WriteLine ("Invalid operator");
}
}
}
}
4. By Akhilan Ganeshkumar
C Sharp calculator by Akhilan Ganeshkumar. Enter the calculation in separate lines, first enter first number, then in second line enter the operator after that in third line enter second number. ( Source )
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SoloLearn
{
class Program
{
static void Main(string[] args)
{
double x = Convert.ToDouble(Console.ReadLine());
string operatori = Console.ReadLine(); // its operatori because in c# theres already an operator keyword.
double y = Convert.ToDouble(Console.ReadLine());
if (operatori == "+") {
Console.WriteLine(x + y);
}
else if (operatori == "-") {
Console.WriteLine(x - y);
}
else if (operatori == "*") {
Console.WriteLine(x * y);
}
else if (operatori == "/") {
try {
Console.WriteLine(x / y);
}
catch (DivideByZeroException ez) {
Console.WriteLine("You can't divide by zero.");
}
}
else {
Console.WriteLine("make sure that the operator is +(addition), -(subtraction), *(multiplication), or /(division).");
}
}
}
}
5. By Sad_Dev
Made by Sad_Dev. You have to first enter the first number in first line, then the operator in second line and after that the second number in third line. ( Source )
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Sololearn
{
class Program
{
static void Main(string[] args)
// Created by Sad_Dev
// Please, enter data like this:
// First number
// Operation (+,-,*,/)
// Second number
// Fot exemple:
// 50
// +
// 60
{
double n1 = double.Parse(Console.ReadLine());
string op = Console.ReadLine();
double n2 = double.Parse(Console.ReadLine());
switch (op)
{
case "+":
double r1 = n1 + n2;
Console.WriteLine("{0} + {1} = {2}",n1, n2, r1);
break;
case "-":
double r2 = n1 - n2;
Console.WriteLine("{0} - {1} = {2}",n1, n2, r2);
break;
case "*":
double r3 = n1 * n2;
Console.WriteLine("{0} * {1} = {2}",n1, n2, r3);
break;
case "/":
double r4 = n1 / n2;
Console.WriteLine("{0} / {1} = {2}",n1, n2, r4);
break;
default :
Console.WriteLine("Something is wrong");
break;
}
}
}
}
6. By Sazo
Made by Sazo. You have to first enter the two numbers you want to calculate, after that enter the operator you want to use. ( Source )
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SoloLearn
{
class Program
{
static void Main(string[] args)
{
Calculator();
}
static void Calculator()
{
double num01;
double num02;
string Op;
string somma;
somma="";
Console.Write("insert a number:");
num01=double.Parse(Console.ReadLine());
Console.WriteLine(somma+num01);
Console.Write("insert another number:");
num02=double.Parse(Console.ReadLine());
Console.WriteLine(somma+num02);
Console.Write("insert an operator:");
Op=Console.ReadLine();
Console.WriteLine(Op);
Console.Write("{0} {1} {2} = ",num01,Op,num02);
if(Op == "-"){
Console.Write(num01-num02);
}
else if(Op == "+"){
Console.Write(num01+num02);
}
else if(Op == "*"){
Console.Write(num01*num02);
}
else if(Op == "/"){
if(num02 == 0){
Console.Write("Division by 0 is impossible.");
}
else{
Console.Write(num01/num02);
}
}
else if(Op == "%"){
Console.Write(num01%num02);
}
else{
Console.WriteLine("Error,({0}) is not a valid operator please try again",Op);
Console.WriteLine(somma);
}
}
}
}
7. By Jomm
Made by Jomm. You have to first enter a number then the operator you want to use after that the second number. ( Source )
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Calculator
{
class Program
{
static void Main(string[] args)
{
Console.Write("Enter number here -> ");
Double a = Convert.ToDouble(Console.ReadLine());
Console.Write("Enter operator here -> ");
string Oper = Console.ReadLine();
Console.Write("Enter second number here -> ");
Double b = Convert.ToDouble(Console.ReadLine());
if (Oper == "-")
{
Console.WriteLine(a - b);
}
if (Oper == "+")
{
Console.WriteLine(a + b);
}
if (Oper == "*")
{
Console.WriteLine(a * b);
}
if (Oper == "/")
{
Console.WriteLine(a / b);
}
else
{
Console.WriteLine("ERROR");
}
}
}
}
8. By Hatem Dbais
Made by Hatem Dbais. First enter the two numbers then select the operator you want to use, if you enter a wrong operator option then the program will ask for input again. ( Source )
using System;
using static System.Console;
namespace Calculator
{
class Program
{
static void Main(string[] args)
{
Title = "Calculator v1.2";
num1:Write("Enter #1: ");
double myFirstNumber;
try
{
myFirstNumber = double.Parse(ReadLine());
}
catch (Exception e)
{
WriteLine("error....");
Beep();
goto num1;
}
num2:Write("Enter #2: ");
double mySecondNumber;
try
{
mySecondNumber = double.Parse(ReadLine());
}
catch (Exception e)
{
WriteLine("error....");
Beep();
goto num2;
}
WriteLine(" \n 1. +\n 2. -\n 3. *\n 4. /\n ");
opr:Write("Choose Operation:");
string oper = ReadLine();
double SUM = myFirstNumber + mySecondNumber;
double minus = myFirstNumber - mySecondNumber;
double multiply = myFirstNumber * mySecondNumber;
double divid = myFirstNumber / mySecondNumber;
switch (oper)
{
case "1":
WriteLine($"\n {myFirstNumber} + {mySecondNumber} = {SUM}");
break;
case "2":
WriteLine($"\n {myFirstNumber} - {mySecondNumber} = {minus}");
break;
case "3":
WriteLine($"\n {myFirstNumber} * {mySecondNumber} = {multiply}");
break;
case "4":
WriteLine($"\n {myFirstNumber} / {mySecondNumber} = {divid}");
break;
default:
Beep();
WriteLine("error....");
goto opr;
}
WriteLine("\n\n\nDeveloped By : \"Mr.HATEM\". (;\n");
goto num1;
}
}
}
9. By Vaibhav Singh
Made by Vaibhav Singh. You have to enter first number then the operator then the second number to get the output. ( Source )
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SoloLearn
{
class Program
{
static void Main(string[] args)
{
Console.Write("Enter a number: ");
double num1 = Convert.ToDouble(Console.ReadLine());
Console.Write("Enter an operator: ");
string op = Console.ReadLine();
Console.Write("Enter another number: ");
double num2 = Convert.ToDouble(Console.ReadLine());
if (op == "+")
{
Console.WriteLine(num1 + num2);
}
else if (op == "-")
{
Console.WriteLine(num1 - num2);
}
else if (op == "*")
{
Console.WriteLine(num1 * num2);
}
else if (op == "/")
{
Console.WriteLine(num1 / num2);
}
else
{
Console.WriteLine("Invalid operator");
}
Console.ReadLine();
}
}
}
10. By Juraj Siman
C Sharp calculator by Juraj Siman. You have to enter the calculation in multiple lines, first enter first number in first line, operator in second line and second number in third line. After that you will get the result. You can also do multiple calculations without restarting the program by entering ‘next’. ( Source )
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SoloLearn
{
class Program
{
static void Main(string[] args)
{
string nextCalc;
do{
double num1 = double.Parse(Console.ReadLine());
string op = Console.ReadLine();
double num2 = double.Parse(Console.ReadLine());
switch (op)
{
case "+":
double res1 = num1 + num2;
Console.WriteLine("{0} + {1} = {2}",num1, num2, res1);
break;
case "-":
double res2 = num1 - num2;
Console.WriteLine("{0} - {1} = {2}",num1, num2, res2);
break;
case "*":
double res3 = num1 * num2;
Console.WriteLine("{0} * {1} = {2}",num1, num2, res3);
break;
case "/":
double res4 = num1 / num2;
Console.WriteLine("{0} / {1} = {2}",num1, num2, res4);
break;
default :
Console.WriteLine("unknown operation");
break;
}
nextCalc = Console.ReadLine();
}while(nextCalc == "next");
Console.WriteLine(" \n if you liked it please leave an upvote");
}
}
}
11. By Ali Sameh Eldeba
Made by Ali Sameh Eldeba. Enter first number then the second number and at last enter the operator you want to use. To run the program again type ‘yes’, to close the program type ‘no’. ( Source )
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SoloLearn
{
class Program
{
public static void Main()
{
Console.Title = "Calculator";
double number1 = 1; //this is a Variable number that You Insert!
double number2 = 1; //this is a Variable number that You Insert!
int IMP = 1; //this is a trick for while loop
int IMP2 = 1; //this is a trick for while loop
while (IMP == 1) //while loop
{
IMP++; //this is a trick for while loop
try //try and catch method
{
Console.WriteLine("\aEnter Your First Number!"); //printing
number1 = Convert.ToDouble(Console.ReadLine()); //letting you to Enter a number
Console.WriteLine("\aEnter Your Second Number!"); //printing
number2 = Convert.ToDouble(Console.ReadLine()); //letting you to Enter a number
string choose = "a"; //making a string variable
double currentvalue = 1; //making a double value
while (IMP2 == 1) //while loop inside while loop
{
Console.WriteLine("Choose Your Symbol (+), (-), (x) or (%)"); //printing
Console.WriteLine(" Or Type Plus,Minus,Multiply,Devide"); //printing
choose = Console.ReadLine(); //letting you to Choose Your Symbol
IMP2++; //while trick
if (choose == "+") //if method
{
currentvalue = number1 + number2; //making the sum
Console.WriteLine("Answer is :" + currentvalue); //printing
ask(); //going to ask method
}
else if (choose == "plus") //else if method
{
currentvalue = number1 + number2; //making the sum
Console.WriteLine("Answer is :" + currentvalue); //printing
ask(); //going to ask method
}
else if (choose == "Plus") //else if method
{
currentvalue = number1 + number2; //making the sum
Console.WriteLine("Answer is :" + currentvalue); //printing
ask(); //going to ask method
}
else if (choose == "PLUS") //else if method
{
currentvalue = number1 + number2; //making the sum
Console.WriteLine("Answer is :" + currentvalue); //printing
ask(); //going to ask method
}
else if(choose == "-") //else if method
{
currentvalue = number1 - number2; //making the destribution
Console.WriteLine("Answer is :" + currentvalue); //printing
ask(); //going to ask method
}
else if(choose == "_") //else if method
{
currentvalue = number1 - number2; //making the destribution
Console.WriteLine("Answer is :" + currentvalue); //printing
ask(); //going to ask method
}
else if(choose == "minus") //else if method
{
currentvalue = number1 - number2; //making the destribution
Console.WriteLine("Answer is :" + currentvalue); //printing
ask(); //going to ask method
}
else if(choose == "Minus") //else if method
{
currentvalue = number1 - number2; //making the destribution
Console.WriteLine("Answer is :" + currentvalue); //printing
ask(); //going to ask method
}
else if(choose == "MINUS") //else if method
{
currentvalue = number1 - number2; //making the destribution
Console.WriteLine("Answer is :" + currentvalue); //printing
ask(); //going to ask method
}
else if(choose == "x") //else if method
{
currentvalue = number1 * number2; //making the multiply
Console.WriteLine("Answer is :" + currentvalue); //printin
ask(); //going to ask method
}
else if(choose == "multiply") //else if method
{
currentvalue = number1 * number2; //making the multiply
Console.WriteLine("Answer is :" + currentvalue); //printing
ask(); //going to ask method
}
else if(choose == "Multiply") //else if method
{
currentvalue = number1 * number2; //making the multiply
Console.WriteLine("Answer is :" + currentvalue); //printing
ask(); //going to ask method
}
else if(choose == "MULTIPLY") //else if method
{
currentvalue = number1 * number2; //making the multiply
Console.WriteLine("Answer is :" + currentvalue); //printing
ask(); //going to ask method
}
else if(choose == "*") //else if method
{
currentvalue = number1 * number2; //making the multiply
Console.WriteLine("Answer is :" + currentvalue); //printing
ask(); //going to ask method
}
else if(choose == "%") //else if method
{
currentvalue = number1 / number2; //making the Devision
Console.WriteLine("Answer is :" + currentvalue); //printing
ask(); //going to ask method
}
else if(choose == "/") //else if method
{
currentvalue = number1 / number2; //making the Devision
Console.WriteLine("Answer is :" + currentvalue); //printing
ask(); //going to ask method
}
else if(choose == "÷") //else if method
{
currentvalue = number1 / number2; //making the Devision
Console.WriteLine("Answer is :" + currentvalue); //printing
ask(); //going to ask method
}
else if(choose == "devide") //else if method
{
currentvalue = number1 / number2; //making the Devision
Console.WriteLine("Answer is :" + currentvalue); //printing
ask(); //going to ask method
}
else if(choose == "Devide") //else if method
{
currentvalue = number1 / number2; //making the Devision
Console.WriteLine("Answer is :" + currentvalue); //printing
ask(); //going to ask method
}
else if(choose == "DEVIDE") //else if method
{
currentvalue = number1 / number2; //making the Devision
Console.WriteLine("Answer is :" + currentvalue); //printing
ask(); //going to ask method
}
else //else method
{
Console.WriteLine("Please Choose Your Symbol"); //printing
IMP2--;
continue; //goint to while method
}
}
Console.ReadKey(); //preventing the console from closing
}
catch //catch method
{
Console.WriteLine("Please Enter Numbers Only!"); //printing
IMP--; //while trick
continue; //goint to while method
}
}
Console.ReadKey(); //preventing the console from closing
}
static void ask() //ask method
{
string tell = "a"; //string Variable
while (tell == "a") //while loop
{
Console.WriteLine("Do You Want To Make Another Equation?"); //printing
tell = Console.ReadLine(); //letting you to Answser
if (tell == "yes" || tell == "Yes" || tell == "YES") //if method
{
Main(); //going to main method
}
else if (tell == "no" || tell == "No" || tell == "NO") //else if method
{
System.Environment.Exit(0); //Exiting the program
}
else // else method
{
Console.WriteLine("Please Enter (yes) or (no) only"); //pinting
tell = "a"; //while trick
continue; //going to while method
}
Console.ReadKey(); //previnting console from closing
}
}
}
}
12. By Hatem Dbais
Another C Sharp calculator by Hatem Dbais. You have to only enter the two numbers of the calculation and the program will print out the results using all the basic operators. ( Source )
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SoloLearn
{
class Program
{
static void Main(string[] args)
{
Console.Title = "Calculator v1.1";
Console.Write("Enter #1: ");
double myFirstNumber = double.Parse(Console.ReadLine());
Console.Write("Enter #2: ");
double mySecondNumber = double.Parse(Console.ReadLine());
double SUM = myFirstNumber + mySecondNumber;
double minus = myFirstNumber - mySecondNumber;
double multiply = myFirstNumber * mySecondNumber;
double divid = myFirstNumber / mySecondNumber;
Console.WriteLine("");
Console.WriteLine(" {0} + {1} = {2}",myFirstNumber,mySecondNumber,SUM);
Console.WriteLine("");
Console.WriteLine(" {0} - {1} = {2}",myFirstNumber,mySecondNumber,minus);
Console.WriteLine("");
Console.WriteLine(" {0} * {1} = {2}",myFirstNumber,mySecondNumber,multiply);
Console.WriteLine("");
Console.WriteLine(" {0} / {1} = {2}",myFirstNumber,mySecondNumber,divid);
Console.WriteLine("");
Console.WriteLine("");
Console.WriteLine("");
Console.WriteLine("");
Console.WriteLine("");
Console.WriteLine("");
Console.WriteLine("");
Console.WriteLine("");
Console.WriteLine("");
Console.WriteLine("This Program Is Developed By : Mr.HATEM. (;");
Console.ReadLine();
}
}
}
13. By Dhany Yudistira
Made by Dhany Yudistira. You have to enter the calculation in one single line with first number then operator then second number, multiple numbers and operators are also supported. ( Source )
using System;
using Dhany;
class Program {
private static void Main(string[] args) {
string input = Console.ReadLine();
double result = Calculator.Start(input);
Console.WriteLine(result);
Calculator.Instructions(input);
}
}
namespace Dhany {
public static class Calculator {
const string OPERATORS = "%*/+—";
public static void Instructions(string input) {
input = Fix(input);
if (!Valid(input)) {
Console.WriteLine("Error: Unable to start the calculator");
return;
}
// Calculate the operation %, *, and /. first
Calculate(ref input, true, '%', '*', '/');
// Then calculate the operation +, and —.
Calculate(ref input, true, '+', '—');
}
public static double Start(string input, bool instructions = false) {
input = Fix(input); // Fix before validating
if (!Valid(input)) {
Console.WriteLine("Error: Unable to start the calculator");
return 0;
}
// Calculate the operation %, *, and /. first
Calculate(ref input, instructions, '%', '*', '/');
// Then calculate the operation +, and —.
Calculate(ref input, instructions, '+', '—');
return Convert.ToDouble(input);
}
private static string Fix(string input) {
// So there is no need to distinguish whether it is lowercase or uppercase
// when using a Valid() method
input = input.ToLower();
input = input.Replace(" ", ""); // To remove spaces
input = input.Replace(",", "."); // To calculate decimal numbers
// Does not support brackets at this time
input = input.Replace("(", "");
input = input.Replace(")", "");
// Change operators character if this happens like
// 10-(-20) or 10--20 which reads ten minus negative twenty
//
// To distinguish negative numbers or operators
// In this code use — as operator and - as a negative number
input = input.Replace("--", "—-");
// The code above only change part of and
// the code below changes the rest
{ // Change operators - to —
string tempInput = string.Empty; // This variable to recreate the input
for (int i = 0; i < input.Length; i++) { // See per character from input
// If the first character is -, it is considered a negative number
if (input[i] == '-' && i == 0) {
tempInput += input[i];
}
// If the current character is - and the previous character is a number
// it is considered an operator
else if (input[i] == '-' && !OPERATORS.Contains(input[i - 1].ToString())) {
tempInput += '—'; // Add — instead of -
}
else {
tempInput += input[i];
}
}
input = tempInput;
}
return input;
}
private static void Calculate(ref string input, bool instructions, params char[] operators) {
int operatorCount = OperatorCount(input, operators);
if (operatorCount == 0) {
return;
}
for (int i = 0; i < operatorCount; i++) {
if (OperatorCount(input, operators) == 0) {
return;
}
double firstOperand = default(double), secondOperand = default(double);
int operatorIndex = default(int); // For the earliest operator index
{ // Take the earliest operator
int[] tempOperatorIndex = new int[operators.Length];
for (int j = 0; j < tempOperatorIndex.Length; j++) {
tempOperatorIndex[j] = input.IndexOf(operators[j]);
}
Array.Sort(tempOperatorIndex);
for (int k = 0; k < tempOperatorIndex.Length; k++) {
if (tempOperatorIndex[k] != -1) { // If operator is exist
operatorIndex = tempOperatorIndex[k];
break;
}
}
}
{ // Take the first operand, check from operator to the left
string tempOperand = string.Empty;
for (int j = operatorIndex - 1; j >= 0 && !IsOperator(input[j]); j--) {
tempOperand = input[j] + tempOperand;
}
firstOperand = Convert.ToDouble(tempOperand);
}
{ // Take the second operand, check from operator to the right
string tempOperand = string.Empty;
for (int j = operatorIndex + 1; j < input.Length && !IsOperator(input[j]); j++) {
tempOperand += input[j];
}
secondOperand = Convert.ToDouble(tempOperand);
}
double result = 0;
switch (input[operatorIndex]) {
case '%':
result = firstOperand % secondOperand;
break;
case '*':
result = firstOperand * secondOperand;
break;
case '/':
result = firstOperand / secondOperand;
break;
case '+':
result = firstOperand + secondOperand;
break;
case '—':
result = firstOperand - secondOperand;
break;
}
string calculating = firstOperand.ToString() + input[operatorIndex].ToString() + secondOperand.ToString();
if (instructions) {
Console.WriteLine(input.Replace(calculating, $"({calculating})").Replace('—', '-'));
for (int j = 0; j <= operatorIndex; j++) {
Console.Write(" ");
}
Console.WriteLine($"= {result}");
}
input = input.Replace(calculating, result.ToString());
}
}
private static bool IsOperator(char input) {
if (OPERATORS.Contains(input.ToString())) {
return true;
}
else {
return false;
}
}
private static int OperatorCount(string input, params char[] operators) {
int count = 0;
foreach (char k in input) { // See the input
if (operators.Length == 0) {
foreach (char l in OPERATORS) { // See the OPERATORS
if (k == l) {
count++;
}
}
}
else {
foreach (char l in operators) { // See the operators
if (k == l) {
count++;
}
}
}
}
return count;
}
private static bool Valid(string input) {
const string VALID_CHARACTERS = "0123456789%*/+—-.";
bool haveOperators = false, validInput = true, validOperands = true;
// Check for invalid characters
for (int i = 0; i < input.Length; i++) { // See the input
if (!VALID_CHARACTERS.Contains(input[i].ToString())) {
validInput = false;
Console.WriteLine($"[{input}]");
for (int j = 0; j <= i; j++) {
Console.Write(" ");
}
Console.WriteLine("^");
Console.WriteLine($"Error: Invalid character found at index {i} with the \'{input[i]}\' character");
}
}
{ // Check for operands
string[] operands = input.Split(new char[] { '%', '*', '/', '+', '—' });
for (int i = 0; i < operands.Length; i++) { // See the operands
if (string.IsNullOrEmpty(operands[i])) { // If the operand is empty / null
int operatorsCount = 0;
string tempInput = input + "]";
string showError = "[";
foreach (char k in tempInput) {
if (operatorsCount == i) {
showError += "?";
}
if (OPERATORS.Contains(k.ToString())) {
operatorsCount++;
}
showError += k;
}
Console.WriteLine(showError);
for (int j = 0; j < showError.IndexOf('?'); j++) {
Console.Write(" ");
}
Console.WriteLine("^");
Console.WriteLine($"Error: Operand {i + 1} is empty");
validOperands = false;
}
}
}
// Check for operators
if (OperatorCount(input) == 0) {
Console.WriteLine($"Error: Operator not found");
}
else {
haveOperators = true;
}
if (!haveOperators || !validInput || !validOperands) {
return false;
}
else {
return true;
}
}
}
}
14. By Charlie
Made by Charlie. Enter first number in first line, second number in second line after that enter what you want to do in third line, 1 = Add, 2 = Subtract, 3 = Multiply and 4 = Divide. ( Source )
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SoloLearn
{
class Program
{
static void Main(string[] args)
{
int num1 = Convert.ToInt32(Console.ReadLine());
int sum = Convert.ToInt32(Console.ReadLine());
int num2 = Convert.ToInt32(Console.ReadLine());
int answer = 0;
Console.WriteLine("Calculator");
switch (sum)
{
case 1:
answer = (num1 + num2);
break;
case 2:
answer = (num1 - num2);
break;
case 3:
answer = (num1 * num2);
break;
case 4:
answer = (num1 / num2);
break;
}
Console.WriteLine("Answer: " + answer);
}
}
}
15. By IT Wraith
Made by IT Wraith. First you have to enter the operator you want to use, after that below that enter the two numbers in different lines. The program will restart after giving the results. ( Source )
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SoloLearn
{
class Program
{
static void Calculator ()
{
do
{
Console.WriteLine ("Put a sign: + or - or * or / ");
string sing = Console.ReadLine();
if (sing == "exit")
{
break;
}
//exit check
int number_1 = Convert.ToInt32(Console.ReadLine());
//first number
int number_2 = Convert.ToInt32(Console.ReadLine());
//second number
switch (sing)
{
case "+":
int sum_1 = number_1 + number_2;
Console.WriteLine("\n "+number_1 + " + " + number_2 + " = " + sum_1);
break;
//numbers are added
case "-":
int sum_2 = number_1 - number_2;
Console.WriteLine("\n "+number_1 + " - " + number_2 + " = " + sum_2);
break;
//numbers are subtracted
case "*":
int sum_3 = number_1 * number_2;
Console.WriteLine("\n "+number_1 + " * " + number_2 + " = " + sum_3);
break;
//numbers multiply
case "/":
int sum_4 = number_1 / number_2;
Console.WriteLine("\n "+number_1 + " / " + number_2 + " = " + sum_4);
break;
}
// check for sign
Console.WriteLine (" \n to exit enter exit \n");
//how are you
} while (true);
}
static void Main(string[] args)
{
Calculator ();
}
}
}
16. By Mohammed Ismail
Made by Mohammed Ismail. You have to enter the first number in first line, operator in second line and the second number in third line. ( Source )
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Sololearn
{
class Program
{
static void Main(string[] args)
{
//write a number in the first line
//then a operator + , - , * or / in the second line
//then the second number in the third line
decimal num1 = Convert.ToDecimal(Console.ReadLine());
string op = Console.ReadLine();
decimal num2 = Convert.ToDecimal(Console.ReadLine());
if(op == "+")
{
Console. WriteLine(num1 + num2);
}
else if(op == "-")
{
Console. WriteLine(num1 - num2);
}
else if(op == "*")
{
Console. WriteLine(num1 * num2);
}
else if(op == "/")
{
Console. WriteLine(num1 / num2);
}
else
{
Console. WriteLine("incorrect operator");
}
}
}
}
17. By Tam
Made by Tam. You have to first enter the operator you want to use, after that enter the two numbers of the calculation one by one in different lines. ( Source )
using System;
namespace Calculator
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Insert the operator ( + , - , * , / )");
string op = Console.ReadLine();
Console.WriteLine("Insert the nums 1 by 1");
double num1 = Convert.ToDouble(Console.ReadLine());
double num2 = Convert.ToDouble(Console.ReadLine());
switch (op)
{
case "+":
Console.WriteLine(num1 + num2);
break;
case "-":
Console.WriteLine(num1 - num2);
break;
case "*":
Console.WriteLine(num1 * num2);
break;
case "/":
if (num2 == 0)
{
Console.WriteLine("Can't divide by 0");
}
Console.WriteLine(num1 / num2);
break;
default:
Console.WriteLine("Error, invalid operator");
break;
}
}
}
}
18. By Hafiz Ahmad Husaini
Made by Hafiz Ahmad Husaini. Enter first number then operator in second line, then the second number in third line to get the output. ( Source )
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Calculator
{
class Program
{
static void Main(string[] args)
{
double num1 = Convert.ToDouble(Console.ReadLine());
string method = Console.ReadLine();
double num2 = Convert.ToDouble(Console.ReadLine());
if(method == "+")
{
double result = num1 + num2;
Console.WriteLine(num1 + " + " + num2 + " = " + result);
}
else if(method == "-")
{
double result = num1 - num2;
Console.WriteLine(num1 + " - " + num2 + " = " + result);
}
else if(method == "x" || method == "X")
{
double result = num1 * num2;
Console.WriteLine(num1 + " X " + num2 + " = " + result);
}
else if(method == ":")
{
double result = num1 / num2;
Console.WriteLine(num1 + " : " + num2 + " = " + result);
}
else
{
Console.WriteLine("ERROR");
}
}
}
}
19. By Tejas Chichkar
Made by Tejas Chichkar. The calculator is not Interactive so you need to change the integers in the program itself. Change int a and int b to the numbers you want to do calculations with. ( Source )
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SoloLearn
{
class Calculator
{
static void Sqr(int x)
{
x = x * x;
Console.WriteLine("The Square of the first integer is: ");
Console.WriteLine(x);
}
static void Sum(int x, int y)
{
x = x + y;
Console.WriteLine("The Sum of given integers is: ");
Console.WriteLine(x);
}
static void Sub(int x, int y)
{
if (x > y)
{
x = x - y;
}
else if (y > x)
{
x = y - x;
}
Console.WriteLine("The Subtraction of given integers is: ");
Console.WriteLine(x);
}
static void Multi(int x, int y)
{
x = x * y;
Console.WriteLine("The Multiplication of given integers is: ");
Console.WriteLine(x);
}
static void Div(double x, double y)
{
x = x + y;
if (x > y)
{
x = x / y;
}
else if (y > x)
{
x = y / x;
}
Console.WriteLine("The Division of given integers is: ");
Console.WriteLine(x);
}
static void Main(string[] args)
{
int a = 3;
int b = 11;
Sqr(a);
Sum(a, b);
Sub(a, b);
Multi(a, b);
Div(a, b);
Console.WriteLine("Integers used for the operations are: ");
Console.WriteLine(a);
Console.WriteLine(b);
}
}
}
20. By Romain Delorme
Simple C Sharp calculator by Romain Delorme. Enter first number then the operator in second line after that the second number in third line to get the result. ( Source )
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//This is my first code, I hope you will like it
namespace SoloLearn
{
class Program
{
static void Read(out int x){x=Convert.ToInt32(Console.ReadLine());
}
static void Read(out double x){x=Convert.ToDouble(Console.ReadLine());
}
static void Main(string[] args)
{
double a;
Read (out a);
string ope = Console.ReadLine();
double b;
Read (out b);
switch (ope)
{
case "+":
Console.WriteLine(a+"+"+b+"="+(a+b));
break;
case "*":
Console.WriteLine(a+"*"+b+"="+(a*b));
break;
case "/":
Console.WriteLine(a+"/"+b+"="+(a/b));
break;
case "%":
Console.WriteLine(a+"%"+b+"="+(a%b));
break;
case "-":
Console.WriteLine(a+"-"+b+"="+(a-b));
break;
default:
Console.WriteLine ("error");
break;
}
}
}
}
21. By Ну Да
Made by Ну Да. Enter the calculation in three different lines, first enter number then the operator after that the second number in third line. ( Source )
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SoloLearn
{
class Program
{
static void Main(string[] args)
{
double a , b , c;
char math;
a = Convert.ToDouble(Console.ReadLine());
math = Convert.ToChar(Console.ReadLine());
b = Convert.ToDouble(Console.ReadLine());
switch (math)
{
case '+':
c = a+b;
Console.WriteLine("{0} + {1} = {2}", a , b , c);
break;
case '-':
c = a-b;
Console.WriteLine("{0} - {1} = {2}", a , b , c);
break;
case '*':
c = a*b;
Console.WriteLine("{0} * {1} = {2}", a , b , c);
break;
case '/':
c = a/b;
Console.WriteLine("{0} / {1} = {2}", a , b , c);
break;
}
}
}
}
22. By Devansh Patil
Made by Devansh Patil. You have to first enter the operator you want to use, after that enter the two numbers in two different lines. ( Source )
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SoloLearn
{
class Program
{
static int factorial(int num) {
if (num == 1) {
return 1;
} else {
return num * factorial(num - 1);
}
}
static int modulus(int first, int last) {
if (first > last) {
return first % last;
} else {
return last % first;
}
}
static int floor_divide(int first, int last) {
if (first > last) {
return (first / last) - modulus(first, last);
} else {
return (last / first) - modulus(first, last);
}
}
static void Main(string[] args)
{
string operand = Console.ReadLine();
int first = Convert.ToInt32(Console.ReadLine());
int last = Convert.ToInt32(Console.ReadLine());
switch (operand) {
case "*":
Console.Write(first * last);
break;
case "/":
Console.Write((first > last) ? first / last : last / first);
break;
case "%":
Console.Write((first > last) ? first % last : last % first);
break;
case "+":
Console.Write(first + last);
break;
case "-":
Console.Write((first > last) ? first - last : last - first);
break;
case "***":
Console.Write(factorial(first));
break;
case "**":
Console.Write(Math.Pow(first, last));
break;
case "//":
Console.Write(floor_divide(first, last));
break;
default:
Console.Write("Unknown operand");
break;
}
}
}
}
23. By Farhadul Kabir
Made by Farhadul Kabir. Enter first number then the operator then the second number, all in separate lines. ( Source )
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SoloLearn
{
class Program
{
static void Main(string[] args)
{
double x, y;
string op;
x = Convert.ToDouble(Console.ReadLine());
op = Console.ReadLine();
y = Convert.ToDouble(Console.ReadLine());
if(op == "+")
{Console.WriteLine(x+y);}
if(op == "-")
{Console.WriteLine(x-y);}
if(op == "/")
{Console.WriteLine(x/y);}
if(op == "*")
{Console.WriteLine(x*y);}
else{Console.WriteLine("Invalid operator");}
}
}
}
24. By Kristian
Made by Kristian. Enter first number then the operator then the second number, all in different lines. ( Source )
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SoloLearn
{
class Program
{
static void Main(string[] args)
{
int x, y;
x = Convert.ToInt32(Console.ReadLine());
string opera = Console.ReadLine();
y = Convert.ToInt32(Console.ReadLine());
if (opera == "+")
{
Console.WriteLine(x + y);
}
else if (opera == "-")
{
Console.WriteLine( x - y);
}
else if (opera == "*")
{
Console.WriteLine(x * y);
}
else if (opera == "/")
{
Console.WriteLine(x/y);
}
}
}
}
25. By Zave
C Sharp Calculator by Zave. Enter the calculation in one single line with spaces in between the numbers and operator. ( Source )
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SoloLearn
{
class Program
{
public static void Print(double first, char symbol, double second, double vid){
Console.WriteLine(first + " " + symbol + " " + second + " = " + vid);
}
public static double prf(string first, double cf, double cs, double cv){
if(first == "cf"){
first = Convert.ToString(cf);
}
else if(first == "cs"){
first = Convert.ToString(cs);
}
else if(first == "cv"){
first = Convert.ToString(cv);
}
else{
Convert.ToDouble(first);
}
return Convert.ToDouble(first);
}
public static double prs(string second, double cf, double cs, double cv){
if(second == "cf"){
second = Convert.ToString(cf);
}
else if(second == "cs"){
second = Convert.ToString(cs);
}
else if(second == "cv"){
second = Convert.ToString(cv);
}
else{
Convert.ToDouble(second);
}
return Convert.ToDouble(second);
}
public static double vid(double first, char symbol, double second){
double vid = 0;
switch(symbol){
case '+':
vid = first + second;
Program.Print(first, '+', second, vid);
break;
case '-':
vid = first - second;
Program.Print(first, '-', second, vid);
break;
case '*':
vid = first * second;
Program.Print(first, '*', second, vid);
break;
case '/':
vid = first / second;
Program.Print(first, '/', second, vid);
break;
case '%':
vid = first % second;
Program.Print(first, '%', second, vid);
break;
case '^':
vid = Math.Pow(first, second);
Program.Print(first, '^', second, vid);
break;
case '?':
vid = Math.Sqrt(first);
Console.WriteLine("?" + first + " = " + vid);
break;
}
return vid;
}
static void Main(string[] args){
string str, first, second;
double cf = 0, cs = 0, cv = 0;
Console.WriteLine("Enter the equation or 'stop' or 'info'");
do{
try{
str = Console.ReadLine();
//stop
if (str.Contains("stop")){
break;
}
//info
else if (str.Contains("info")){
Console.WriteLine("Sign '+' for addition, '-' for subtraction, '*' for multiplication, '/' for division, '%' for modular division, '^' for elevation to degree, '?' for square root calculation. You can enter 'cf' or 'cs' or 'cv' to copy the values from the previous equations. 'cf' is required to copy the first value, 'cs' is required to copy the second value, and 'cv' is required to copy the response. If there was no copied value in the previous equation, it will automatically be 0.\n");
continue;
}
//multiplication
else if(str.Contains('*')){
first = Convert.ToString(str.Substring(0, str.IndexOf('*')));
second = Convert.ToString(str.Substring(str.IndexOf('*') + 1));
cv = Program.vid(cf = Program.prf(first, cf, cs, cv), '*', cs = Program.prs(second, cf, cs, cv));
}
// division
else if(str.Contains('/')){
first = Convert.ToString(str.Substring(0, str.IndexOf('/')));
second = Convert.ToString(str.Substring(str.IndexOf('/') + 1));
cv = Program.vid(cf = Program.prf(first, cf, cs, cv), '/', cs = Program.prs(second, cf, cs, cv));
}
// division by module
else if(str.Contains('%')){
first = Convert.ToString(str.Substring(0, str.IndexOf('%')));
second = Convert.ToString(str.Substring(str.IndexOf('%') + 1));
cv = Program.vid(cf = Program.prf(first, cf, cs, cv), '%', cs = Program.prs(second, cf, cs, cv));
}
// elevation to degree
else if(str.Contains('^')){
uint step;
first = Convert.ToString(str.Substring(0, str.IndexOf('^')));
step = Convert.ToUInt32(str.Substring(str.IndexOf('^') + 1));
cv = Program.vid(cf = Program.prf(first, cf, cs, cv), '^', step);
}
//square root
else if(str.Contains('?')){
first = Convert.ToString(str.Substring(1));
cv = Program.vid(cf = Program.prf(first, cf, cs, cv), '?', 0);
}
// addition
else if(str.Contains('+')){
first = Convert.ToString(str.Substring(0, str.IndexOf('+')));
second = Convert.ToString(str.Substring(str.IndexOf('+') + 1));
cv = Program.vid(cf = Program.prf(first, cf, cs, cv), '+', cs = Program.prs(second, cf, cs, cv));
}
//subtraction
else if(str.Contains('-')){
first = Convert.ToString(str.Substring(0, str.IndexOf('-')));
second = Convert.ToString(str.Substring(str.IndexOf('-') + 1));
cv = Program.vid(cf = Program.prf(first, cf, cs, cv), '-', cs = Program.prs(second, cf, cs, cv));
}
else{
Console.WriteLine("You entered the equation incorrectly");
}
Console.WriteLine(" ");
}
catch(FormatException e){
Console.WriteLine("\nFormat Exeption\n");
continue;
}
catch(Exception e){
Console.WriteLine("Error: " + e.Message);
continue;
}
}while(true);
}
}
}
26. By Maxim Kolpakov
Made by Maxim Kolpakov. Enter first and second number to get its addition. ( Source )
1 1 2
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SoloLearn
{
class Program
{
static void Main(string[] args)
{
int x = Convert.ToInt32 (Console.ReadLine());
int y = Convert.ToInt32 (Console.ReadLine());
int z = x+y;
Console.WriteLine (z);
Console.ReadKey ();
}
}
}
27. By Muqtda Ali
Made by Muqtda Ali. Select the operation your want to use, after that enter the numbers. ( Source )
1 you choose + way the number1 =2 the number2 =2 now2+2=4
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SoloLearn
{
class Program
{
static void Main(string[] args)
{
// mathway ( 1=+ // 2=× // 3=÷ // 4=- )
int mathway;
mathway = Convert.ToInt32(Console.ReadLine());
if (mathway == 1) {
Console.WriteLine ("you choose + way");
int x = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(" the number1 ="+x);
int y = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(" the number2 ="+y);
int result= x+y;
Console.WriteLine ("now"+x+"+"+y+"="+result);
} else if (mathway == 2) {
Console.WriteLine ("you choose × way");
int x = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(" the number1 ="+x);
int y = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(" the number2 ="+y);
int result= x*y;
Console.WriteLine ("now "+x+"×"+y+" ="+result);
} else if (mathway == 3)
{
Console.WriteLine ("you choose ÷ way");
double x = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(" the number1 ="+x);
double y = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(" the number2 ="+y);
double result= x/y;
Console.WriteLine ("now "+x+"/"+y+" = "+result);
} else if (mathway == 4)
{
Console.WriteLine ("you choose - way");
int x = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(" the number1 ="+x);
int y = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(" the number2 ="+y);
int result= x-y;
Console.WriteLine ("now "+x+" - "+y+" = " +result);
}
}
}
}
28. By Stark
Made by Stark. Simple C# Calculator, enter numbers then select operation. ( Source )
ENTER A NUMBER ENTER ANOTHER NUMBER 5 ENTER THE CHOICE 5 ENTER 1 FOR SUM 2 FOR DIFFERENCE 3 FOR MULTIPLY 4 FOR DIVIDE 1 10
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SoloLearn
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("ENTER A NUMBER");
int a=Convert.ToInt32(Console.ReadLine());
Console.WriteLine("ENTER ANOTHER NUMBER");
Console.WriteLine(a);
int b=Convert.ToInt32(Console.ReadLine());
Console.WriteLine("ENTER THE CHOICE");
Console.WriteLine(b);
Console.WriteLine("ENTER 1 FOR SUM\n2 FOR DIFFERENCE\n3FOR MULTIPLY\n4FOR DIVIDE");
int choice=Convert.ToInt32(Console.ReadLine());
Console.WriteLine(choice);
switch(choice)
{
case 1:
{
Console.WriteLine(a+b);
break;
}
case 2:
{
Console.WriteLine(a-b) ;
break;
}
case 3:
{
Console.WriteLine(a*b);
break;
}
case 4:
{
Console.WriteLine(a/b);
break;
}
default :
{
Console.WriteLine("INVALID");
Console.Beep();
break;
}
}
}
}
}
29. By Bahareh Talebi
Made by Bahareh Talebi. ( Source )
Enter 1st Number: 6 Choose Opeartion (+, -, /, *): + Enter Second Operation: 6 6 + 6 = 12
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SoloLearn
{
class Program
{
static void Main(string[] args)
{
int num1;
int num2;
string operand;
float answer;
Console.Write("Enter 1st Number: ");
num1 = Convert.ToInt32(Console.ReadLine());
Console.Write("Choose Opeartion (+, -, /, *): ");
operand = Console.ReadLine();
Console.Write("Enter Second Operation: ");
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();
}
}}
30. By Alex
Made by Alex. ( Source )
12 + 12 12+12=24
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SoloLearn
{
class Program
{
static void Main(string[] args)
{
try
{
int a = Convert.ToInt32(Console.ReadLine());
char f = Convert.ToChar(Console.ReadLine());
int b = Convert.ToInt32(Console.ReadLine());
void wrt()
{
Console.Write("{0}{1}{2}=",a,f,b);
}
switch(f)
{
case '+':
wrt();
Console.WriteLine(a+b);
break;
case '-':
wrt();
Console.WriteLine(a-b);
break;
case '*':
wrt();
Console.WriteLine(a*b);
break;
case '/':
wrt();
Console.WriteLine(a/b);
break;
case '^':
wrt();
Console.WriteLine(Math.Pow(a,b));
break;
default:
Console.WriteLine("Incorrect function");
break;
}
}
catch (DivideByZeroException)
{
Console.WriteLine("/ 0 EXCEPTION");
}
catch (Exception)
{
Console.WriteLine("Other error");
}
}
}
}
31. By Meh
Made by Meh. ( Source )
Operation: + First Number 4 Second Number 4 Result 8
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SoloLearn
{
class Program
{
static void Main(string[] args)
{
while (true)
{
string operand=Console.ReadLine();
if (operand=="exit")
{
Console.WriteLine("Program ending");
break;
}
Console.WriteLine("Operation: {0}",operand);
int x=Convert.ToInt32(Console.ReadLine());
Console.WriteLine("First Number {0}",x);
int y=Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Second Number {0}",y);
int result=0;
switch (operand)
{
case "add":
result=x+y;
break;
case "subtract":
result=x-y;
break;
case "divide":
result=x/y;
break;
case "multiply":
result=x*y;
break;
}
Console.WriteLine("Result {0}",result);
}
}
}
}
32. By Conner Gority
Made by Conner Gority. ( Source )
1 + 4 5
/*
By: Conner Gority
When doing input do it like this:
Number
Symbol
Number
Ex:
25
+
25
Answer: 50
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SoloLearn{
class Calculator{
static int Add(int a, int b){
return a+b;
}
static int Multiply(int a, int b){
return a*b;
}
static int Divide(int a, int b){
if(a > b){
return a/b;
}
else{
return b/a;
}
}
static int Remainder(int a, int b){
if(a > b){
return a%b;
}
else{
return b%a;
}
}
static int Subtract(int a, int b){
return a-b;
}
static void Main(string[] args)
{
int c = 0;
int r = 0;
int a = Convert.ToInt32(Console.ReadLine());
String input = Console.ReadLine();
int b = Convert.ToInt32(Console.ReadLine());
if(input == "+"){
c = Add(a, b);
}
else if(input == "*" || input == "x"){
c = Multiply(a, b);
}
else if(input == "/" || input == "÷"){
c = Divide(a, b);
r = Remainder(a, b);
}
else if(input == "-"){
c = Subtract(a, b);
}
else{
Console.WriteLine("Error");
}
if(r == 0){
Console.WriteLine(c);
}
else{
Console.WriteLine(c + " R:" + r);
}
}
}
}
33. By Milk Bottle
Made by Milk Bottle. You will need to input 3 inputs on 3 lines. The first and third lines are the numbers you will use. The second line is the operator. You can put in +, -, , and /. To square the first line, use ^2, and to cube it, use ^3. Use the same pattern up to the ninth power. You can also square root the first line by making the second line sqrt. The “cbrt” is accurate to the nearest 0.00000000000001. ( Source )
7 + 7 7 + 7 = 14
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
namespace SoloLearn
{
class Program
{
static void Main(string[] args)
{
int a = Convert.ToInt32(Console.ReadLine());
string x = Convert.ToString(Console.ReadLine());
int b = Convert.ToInt32(Console.ReadLine());
int y;
int r;
double s;
switch (x)
{
case "+":
y = a + b;
Console.WriteLine("{0} + {1} = {2}", a, b, y);
break;
case "-":
y = a - b;
Console.WriteLine("{0} - {1} = {2}", a, b, y);
break;
case "*":
y = a * b;
Console.WriteLine("{0} * {1} = {2}", a, b, y);
break;
case "/":
y = a / b;
r = a % b;
if (r==0){
Console.WriteLine("{0} / {1} = {2}", a, b, y);
}
else if (y==0){
Console.WriteLine("{0} / {1} = {2}/{1}", a, b, r);
}
else{
Console.WriteLine("{0} / {1} = {2} {3}/{1}", a, b, y, r);
}
break;
case "^2":
y = a * a;
Console.WriteLine("{0}^2 = {1}", a, y);
break;
case "^3":
y = (a * a) * a;
Console.WriteLine("{0}^3 = {1}", a, y);
break;
case "^4":
y = ((a * a) * a) * a;
Console.WriteLine("{0}^4 = {1}", a, y);
break;
case "^5":
y = (a * a) * a * a * a;
Console.WriteLine("{0}^5 = {1}", a, y);
break;
case "^6":
y = a * a * a * a * a * a;
Console.WriteLine("{0}^6 = {1}", a, y);
break;
case "^7":
y = (a * a) * a * a * a * a * a;
Console.WriteLine("{0}^7 = {1}", a, y);
break;
case "^8":
y = ((a * a) * a) * a * a * a * a * a;
Console.WriteLine("{0}^8 = {1}", a, y);
break;
case "^9":
y = (a * a) * a * a * a * a * a * a * a;
Console.WriteLine("{0}^9 = {1}", a, y);
break;
case "sqrt":
s = Convert.ToDouble(Math.Sqrt(a));
Console.WriteLine("sqrt {0} = {1}", a, s);
break;
case "4":
Console.WriteLine("Pi equals: 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593344612847564823378678316527120190914564856692346034861045432664821339360726024914127372458700660631558817488152092096282925409171536436789259036001133053054882046652138414695194151160943305727036575959195309218611738193261179310511854807446237996274956735188575272489122793818301194912983367336244065664308602139494639522473719070217986094370277053921717629317675238467481846766940513200056812714526356082778577134275778960917363717872 1468440901224953430146549585371050792279689258923542019956112129021960864034418159813629774771309960 5187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881 7101000313783875288658753320838142061717766914730359825349042875546873115956286388235378759375195778 1857780532171226806613001927876611195909216420198938095257201065485863278865936153381827968230301952 0353018529689957736225994138912497217752834791315155748572424541506959508295331168617278558890750983 8175463746493931925506040092770167113900984882401285836160356370766010471018194295559619894676783744 9448255379774726847104047534646208046684259069491293313677028989152104752162056966024058038150193511 2533824300355876402474964732639141992726042699227967823547816360093417216412199245863150302861829745 5570674983850549458858692699569092721079750930295532116534498720275596023648066549911988183479775356 6369807426542527862551818417574672890977772793800081647060016145249192173217214772350141441973568548 1613611573525521334757418494684385233239073941433345477624168625189835694855620992192221842725502542 5688767179049460165346680498862723279178608578438382796797668145410095388378636095068006422512520511 7392984896084128488626945604241965285022210661186306744278622039194945047123713786960956364371917287 46776465757396241389086583264599581339047802759010...");
Console.WriteLine();
Console.WriteLine("Have fun with this\nTry to memorize that or find the long string of nines :-)");
break;
case "cos":
s = Convert.ToDouble(Math.Cos(a));
Console.WriteLine("sin {0} = {1}", a, s);
break;
case "900000000":
Console.WriteLine("NINE HUNDRED MILLION!!!");
break;
case "cbrt":
s = Convert.ToDouble(Math.Pow(a,0.3333333333333333333333333333333333));
Console.WriteLine("cbrt {0}= {1}",a,s);
break;
default:
Console.WriteLine("System.OperationError: operatorInput was invalid in var x");
break;
}
}
}
}