Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace StaticMembersExercises
- {
- public class Program
- {
- public static void Main()
- {
- string line = Console.ReadLine().Trim();
- while (!line.Equals("End"))
- {
- string[] calculationInfo = line.Split(new char[] { }, StringSplitOptions.RemoveEmptyEntries);
- string calculation = calculationInfo[0];
- decimal num1 = decimal.Parse(calculationInfo[1]);
- decimal num2 = decimal.Parse(calculationInfo[2]);
- decimal? result = null;
- if (calculation == "Sum")
- {
- result = MathUtil.Sum(num1, num2);
- }
- else if (calculation == "Multiply")
- {
- result = MathUtil.Multiply(num1, num2);
- }
- else if (calculation == "Percentage")
- {
- result = MathUtil.Percentage(num1, num2);
- }
- else if (calculation == "Divide")
- {
- if (num2 > 0 || num2 < 0)
- {
- result = MathUtil.Divide(num1, num2);
- }
- else
- {
- Console.WriteLine("Infinity");
- }
- }
- else if (calculation == "Subtract")
- {
- result = MathUtil.Subtract(num1, num2);
- }
- if (result != null)
- {
- Console.WriteLine($"{result:F2}");
- }
- line = Console.ReadLine();
- }
- }
- }
- public class MathUtil
- {
- public static decimal Sum(decimal x, decimal y)
- {
- return x + y;
- }
- public static decimal Subtract(decimal x, decimal y)
- {
- return x - y;
- }
- public static decimal Multiply(decimal x, decimal y)
- {
- return x * y;
- }
- public static decimal Divide(decimal x, decimal y)
- {
- //if (y > 0 || y < 0)
- //{
- return x / y;
- //}
- //return 0;
- }
- public static decimal Percentage(decimal totalNumber, decimal percent)
- {
- return totalNumber * percent / 100;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement