c# Console Calc

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.0 kB
7
Indexable
Never
using System;

// Nums defined
int num1 = 0;   int num2 = 0;

// User First Number
Console.WriteLine("Num 1:");
// Google .-. !  andere lösungen fürs converten?
num1 = Convert.ToInt32(Console.ReadLine());

// User Second Number
Console.WriteLine("Num 2:");
num2 = Convert.ToInt32(Console.ReadLine());

// Options
Console.WriteLine("What would you like to do:");
Console.WriteLine("\ta - Add");
Console.WriteLine("\ts - Subtract");
Console.WriteLine("\tm - Multiply");
Console.WriteLine("\td - Divide");
Console.Write("Your option? ");

// Cases
switch (Console.ReadLine())
{
    case "a":
        Console.WriteLine($"Your result: {num1} + {num2} = " + (num1 + num2));
        break;
    case "s":
        Console.WriteLine($"Your result: {num1} - {num2} = " + (num1 - num2));
        break;
    case "m":
        Console.WriteLine($"Your result: {num1} * {num2} = " + (num1 * num2));
        break;
    case "d":
        Console.WriteLine($"Your result: {num1} / {num2} = " + (num1 / num2));
        break;
}