When I debug I cannot keep the console open. No errors.. What am I doing wrong h
ID: 440736 • Letter: W
Question
When I debug I cannot keep the console open. No errors.. What am I doing wrong here. using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace FractionDemo { class Fraction { static void Main(string[] args) { } private int whole; private int numerator; private int denominator; public Fraction() { Whole = 0; Numerator = 0; Denominator = 1; } public Fraction(int numb, int deno) { Whole = 0; Numerator = numb; Denominator = deno; } public Fraction(int w, int numb, int deno) { Whole = w; Numerator = numb; Denominator = deno; } public int Whole { get { return whole; } set { whole = value; } } public int Numerator { get { return numerator; } set { numerator = value; } } public int Denominator { get { return denominator; } set { denominator = value; if (denominator == 0) denominator = 1; } } private int Gcd(int x, int y) { int t; while (y != 0) { t = y; y = x % y; x = t; } return x; } public void Reduce() { whole = whole + numerator / denominator; numerator = numerator % denominator; if (numerator == 0) { denominator = 1; } else { int g = Gcd(numerator, denominator); numerator = numerator / g; denominator = denominator / g; } } public static Fraction operator +(Fraction f1, Fraction f2) { int numb1 = f1.denominator * f1.whole + f1.numerator; int deno1 = f1.denominator; int numb2 = f2.denominator * f2.whole + f2.numerator; int deno2 = f2.denominator; Fraction r = new Fraction(numb1 * deno2 + numb2 * deno1, deno1 * deno2); r.Reduce(); return r; } public override string ToString() { string s = ""; if (whole != 0) s = s + whole; if (numerator != 0) s = s + " " + numerator + "/" + denominator; s = s.Trim(); if (s == "") s = "0"; return s; } } }Explanation / Answer
If the console is closing out on you, you might want to add
Console.ReadLine(); Console.ReadLine();
at the end of your main to stall it from closing for two line reads.
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.