Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Calculator
- {
- internal class Program
- {
- static int AskAboutInteger()
- {
- int val;
- Console.Write($"Enter a number: ");
- val = int.Parse(Console.ReadLine());
- return val; ;
- }
- static int PrintMenu()
- {
- Console.WriteLine("0 - Exit");
- Console.WriteLine("1 - Ask about the numbers");
- Console.WriteLine("2 - Add");
- Console.WriteLine("3 - Sub");
- Console.WriteLine("4 - Multi");
- Console.WriteLine("5 - Div");
- Console.Write("Your choice: ");
- int choice = int.Parse(Console.ReadLine());
- return choice;
- }
- static int Add(int a, int b)
- {
- return a + b;
- }
- static int Sub(int a, int b)
- {
- return a - b;
- }
- static int Multi(int a, int b)
- {
- return a * b;
- }
- static double? Div(int a, int b)
- {
- double? res;
- if (b != 0)
- {
- res = (double)a / b;
- return res;
- }
- else
- {
- Console.Clear();
- Console.WriteLine("\n\n\n\n\n\t\t\t\t\tDon't devide by 0!");
- Console.ReadKey();
- return null;
- }
- }
- static void PrintResult(int a, int b, double? r, char o)
- {
- Console.WriteLine($"\n\n\n\n\n\t\t\t\t\t\t{a} {o} {b} = {r}");
- Console.ReadKey();
- }
- static void Main(string[] args)
- {
- char operation = ' ';
- int decision;
- int num1 = 0, num2 = 0;
- double? result = null;
- do
- { Console.Clear();
- decision = PrintMenu();
- Console.Clear();
- switch (decision)
- {
- case 0:
- Console.WriteLine("\n\n\n\n\n\t\t\t\t\t\tThank you!");
- result = null;
- System.Threading.Thread.Sleep(1000);
- break;
- case 1:
- num1 = AskAboutInteger();
- num2 = AskAboutInteger();
- result = null;
- break;
- case 2:
- result = Add(num1, num2);
- operation = '+';
- break;
- case 3:
- result = Sub(num1, num2);
- operation = '-';
- break;
- case 4:
- result = Multi(num1, num2);
- operation = '*';
- break;
- case 5:
- result = Div(num1, num2);
- operation = '/';
- break;
- }
- if (result != null)
- PrintResult(num1, num2, result, operation);
- } while (decision != 0);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement