Hey, I’m making a calculator in C# using dotnetfiddle terminals, and I was wondering about any additions that you guys would make to it.
It is capable of addition, subtraction, multiplication, division, exponents, logarithms, and whole random number generation (set by user limits).
Here’s the code. If you can find of a way to streamline it, it would also be appreciated.
using System;
public class Program{
public static void Main(){
Console.WriteLine("Welcome to the basic calculator\n-------------------------------\n");
while (true){
Console.WriteLine("Here are the available functions: \n\n1. Addition\n2. Subtraction\n3. Multiplication\n4. Division\n5. Exponent\n6. Logarithm\n7. Random number generator\n\nSelect a function by its number: ");
string pemdas = Console.ReadLine();
if (pemdas == "1"){
Console.WriteLine("insert first number: ");
double firstNum = (double)Convert.ToDouble(Console.ReadLine());
Console.WriteLine("insert second number: ");
double secondNum = (double)Convert.ToDouble(Console.ReadLine());
Console.WriteLine("\nYour result is: " + (firstNum + secondNum) + "\n\n\n");
}else if (pemdas == "2"){
Console.WriteLine("insert starting value: ");
double firstNum = (double)Convert.ToDouble(Console.ReadLine());
Console.WriteLine("insert value removed: ");
double secondNum = (double)Convert.ToDouble(Console.ReadLine());
Console.WriteLine("\n your resulting value is: " + (firstNum - secondNum) + "\n\n\n");
}else if (pemdas == "3"){
Console.WriteLine("Enter your starting value: ");
double firstNum = (double)Convert.ToDouble(Console.ReadLine());
Console.WriteLine("How much are you multiplying this number by: ");
double secondNum = (double)Convert.ToDouble(Console.ReadLine());
Console.WriteLine("\nYour result is: " + (firstNum * secondNum) + "\n\n\n");
}else if (pemdas == "4"){
Console.WriteLine("Enter your starting value: ");
double firstNum = (double)Convert.ToDouble(Console.ReadLine());
Console.WriteLine("How much are you dividing this number by? ");
double secondNum = (double)Convert.ToDouble(Console.ReadLine());
Console.WriteLine("\nYour resulting value is: " + (firstNum / secondNum) + "\n\n\n");
}else if (pemdas == "5"){
Console.WriteLine("Enter your base: ");
if (Console.ReadLine() == "e"){
double baseNum = 2.71828;
Console.WriteLine("Enter the power: ");
double exponent = (double)Convert.ToDouble(Console.ReadLine());
Console.WriteLine("\nYour result is: " + Math.Pow(baseNum, exponent) + "\n\n\n");
}else{
double baseNum = (double)Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Enter the power: ");
double exponent = (double)Convert.ToDouble(Console.ReadLine());
Console.WriteLine("\nYour result is: " + Math.Pow(baseNum, exponent) + "\n\n\n");
}
}else if (pemdas == "6"){
Console.WriteLine("Enter your log base: ");
if(Console.ReadLine() == "e"){
double logBase = 2.71828;
Console.WriteLine("What is the other thing: ");
double thingValue = (double)Convert.ToDouble(Console.ReadLine());
Console.WriteLine("The result is: " + Math.Log(thingValue, logBase));
}else{
double logBase = (double)Convert.ToDouble(Console.ReadLine());
Console.WriteLine("What is the other thing: ");
double thingValue = (double)Convert.ToDouble(Console.ReadLine());
Console.WriteLine("The result is: " + Math.Log(thingValue, logBase));
}
}else if(pemdas=="7"){
Random rnd = new Random();
Console.WriteLine("WHOLE NUMBERS ONLY");
Console.WriteLine("Lower bound: ");
int lowerB = (int)Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Upper bound: ");
int upperB = (int)Convert.ToInt32(Console.ReadLine());
int compChoice = rnd.Next(lowerB, upperB);
}
}
}
}