Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

c# calculator

//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");
            }
Comment

c# calculator

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: +, -, *, /, >, <
        }

    }
}
Comment

calculator in C#

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);
    }
}
Comment

C# Building a Calculator

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();
Comment

PREVIOUS NEXT
Code Example
Csharp :: 2d rotation unity 
Csharp :: c# named parameters 
Csharp :: Throw index out of range C# 
Csharp :: list of list of string to list of string c# 
Csharp :: add row count devepxress report 
Csharp :: how to make colliders collide with some things but not other in unity 
Csharp :: get value from config file c# 
Csharp :: hello world in unity c# 
Csharp :: wpf mouse over style trigger 
Csharp :: binary search c# 
Csharp :: c# input 
Csharp :: how to check if the value is alphabet only in c# 
Csharp :: c# convert double to int 
Csharp :: unity color by rgb 
Csharp :: roman to int 
Csharp :: unity print vs debug log 
Csharp :: wpf arrow button 
Csharp :: multithreading in c# 
Csharp :: unity find child by name 
Csharp :: asp.net textarea disable resize 
Csharp :: c# radio button checked 
Csharp :: c# get excel column number from letter 
Csharp :: c# object list attribute to string 
Csharp :: remove duplicate characters in a string c# 
Csharp :: unity send post request json 
Csharp :: get file path in .net core from wwwroot folder 
Csharp :: how to check if the value is alphabet and numbers only only in c# 
Csharp :: c# verify in class exist in list 
Csharp :: entity framework insert 
Csharp :: unity rigid body variable 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =