Advertisement
Guest User

Untitled

a guest
Aug 10th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. static void Main(string[] args)
  2. {
  3. Console.WriteLine("### Калькулятор v1.0 ####");
  4. while (true)
  5. {
  6. Console.Write("Введите первое число: ");
  7. int num1 = Convert.ToInt32(Console.ReadLine());
  8. Console.WriteLine("Введите слово операции (div - разделить, mul - умножить, add - сложить, sub - вычесть): ");
  9. string word = Console.ReadLine();
  10. Console.Write("Введите второе число: ");
  11. int num2 = Convert.ToInt32(Console.ReadLine());
  12. int result = 0;
  13. if (word == "mul") result = multiply(num1, num2);
  14. else if (word == "div") result = divide(num1, num2);
  15. else if (word == "add") result = add(num1, num2);
  16. else result = subtact(num1, num2);
  17. Console.WriteLine(result);
  18. }
  19. }
  20.  
  21. static int multiply (int num1, int num2)
  22. {
  23. return num1 * num2;
  24. }
  25.  
  26. static int divide (int num1, int num2)
  27. {
  28. return num1 / num2;
  29. }
  30.  
  31. static int add (int num1, int num2)
  32. {
  33. return num1 + num2;
  34. }
  35. static int subtact (int num1, int num2)
  36. {
  37. return num1 - num2;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement