//A simple calculator guide for total c# begginers
//prompts and gathering data
Console.Write("Enter a number: ");
int N1 = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter an operator: ");
string op = Console.ReadLine();
Console.Write("Enter a number: ");
int N2 = Convert.ToInt32(Console.ReadLine());
//if statements
if (op == "+")
{
Console.WriteLine(N1 + N2);
}else if (op == "-")
{
Console.WriteLine(N1 - N2);
}else if (op == "*")
{
Console.WriteLine(N1 * N2);
}else if (op == "/")
{
Console.WriteLine(N1 / N2);
}
else
{
//if not stated operator, say "error"
Console.WriteLine("Error");
}
}
catch
{
//if other problem spotted, say "error
Console.Write("Error");
}
using System;
namespace Calculator
{
class Calculator
{
static void Main(string[] args)
{
// basic homemade calculator vscode c# calculator
Console.Write("Enter a number here: ");
int num1 = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter another number: ");
int num2 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(num1 + num2);
// change the operation if you want to
// ex: +, -, *, /, >, <
}
}
}
using System;
class Program
{
static void Main(string[] args)
{
float ans = 0;
// Asking the user what operator to use by number
Console.WriteLine("(1)Add
(2)Subtract
(3)Multiply
(4)Divide");
Console.WriteLine("Enter an operator: ");
int op = int.Parse(Console.ReadLine());
// Asking the first number and parsing it to a float
Console.WriteLine("Enter the first number: ");
float n1 = float.Parse(Console.ReadLine());
// Asking the second number and parsing it to a float
Console.WriteLine("Enter the second number: ");
float n2 = float.Parse(Console.ReadLine());
// Checking the value of op and then doing the correct operation
if (op == 1)
{
ans = n1 + n2;
}
else if (op == 2)
{
ans = n1 - n2;
}
else if (op == 3)
{
ans = n1 * n2;
}
else if (op == 4)
{
ans = n1 / n2;
}
else
{
Console.WriteLine("Error operator unknown");
}
// Printing the answer
Console.WriteLine("The answer is " + ans);
}
}
Console.Write("Enter a number: ");
double num1 = Convert.ToDouble(Console.ReadLine());
Console.Write("Enter another number: ");
double num2 = Convert.ToDouble(Console.ReadLine());
Console.WriteLine(num1 + num2);
Console.ReadLine();