static void Main(string[] args) { string action = string.Empty; string fractionA = string.Empty; string fractionB = string.Empty; do { Console.WriteLine("Enter +, -, * or / (q to quit)"); action = Console.ReadLine(); if (!(action == "q" || action == "Q")) { Console.WriteLine("Enter the first fraction (example: 1/2):"); fractionA = Console.ReadLine(); Console.WriteLine("Enter the second fraction (example: 5/9):"); fractionB = Console.ReadLine(); Fraction A = new Fraction(fractionA); Fraction B = new Fraction(fractionB); Fraction result = new Fraction(); switch (action) { case "+": result = A + B; break; case "-": result = A - B; break; case "*": result = A * B; break; case "/": result = A / B; break; } Console.WriteLine("The result is: " + result); } } while (!(action == "q" || action == "Q")); }
public static Fraction operator -(Fraction a, Fraction b) { Fraction result = new Fraction(); result.Numerator = (a.Numerator * b.Denominator) - (a.Denominator * b.Numerator); result.Denominator = a.Denominator * b.Denominator; result.Normalize(); return result; }
public bool IsEqualTo(Fraction secondFraction) { return(secondFraction.Denominator / secondFraction.Numerator == Denominator / Numerator); }