Click here to Skip to main content
15,904,935 members
Home / Discussions / C#
   

C#

 
GeneralRe: how to deploy your software (set up) Pin
ago248620-Apr-18 6:30
ago248620-Apr-18 6:30 
Questionconsolidating four similar classes Pin
Alexander Kindel16-Apr-18 15:23
Alexander Kindel16-Apr-18 15:23 
AnswerRe: consolidating four similar classes Pin
#realJSOP17-Apr-18 2:24
professional#realJSOP17-Apr-18 2:24 
GeneralRe: consolidating four similar classes Pin
Alexander Kindel17-Apr-18 11:34
Alexander Kindel17-Apr-18 11:34 
GeneralRe: consolidating four similar classes Pin
#realJSOP17-Apr-18 12:33
professional#realJSOP17-Apr-18 12:33 
GeneralRe: consolidating four similar classes Pin
Alexander Kindel17-Apr-18 16:53
Alexander Kindel17-Apr-18 16:53 
GeneralRe: consolidating four similar classes Pin
#realJSOP19-Apr-18 2:50
professional#realJSOP19-Apr-18 2:50 
AnswerRe: consolidating four similar classes Pin
Gerry Schmitz18-Apr-18 7:05
mveGerry Schmitz18-Apr-18 7:05 
GeneralRe: consolidating four similar classes Pin
Alexander Kindel18-Apr-18 12:11
Alexander Kindel18-Apr-18 12:11 
GeneralRe: consolidating four similar classes Pin
Gerry Schmitz19-Apr-18 8:50
mveGerry Schmitz19-Apr-18 8:50 
QuestionC# Javascript in WebBrowser Pin
unfolded16-Apr-18 8:37
unfolded16-Apr-18 8:37 
AnswerRe: C# Javascript in WebBrowser Pin
Eddy Vluggen17-Apr-18 0:00
professionalEddy Vluggen17-Apr-18 0:00 
GeneralRe: C# Javascript in WebBrowser Pin
unfolded17-Apr-18 1:06
unfolded17-Apr-18 1:06 
GeneralRe: C# Javascript in WebBrowser Pin
Eddy Vluggen17-Apr-18 6:32
professionalEddy Vluggen17-Apr-18 6:32 
GeneralRe: C# Javascript in WebBrowser Pin
unfolded18-Apr-18 8:12
unfolded18-Apr-18 8:12 
AnswerRe: C# Javascript in WebBrowser Pin
Gerry Schmitz18-Apr-18 7:22
mveGerry Schmitz18-Apr-18 7:22 
GeneralRe: C# Javascript in WebBrowser Pin
unfolded18-Apr-18 8:10
unfolded18-Apr-18 8:10 
GeneralRe: C# Javascript in WebBrowser Pin
Gerry Schmitz18-Apr-18 8:59
mveGerry Schmitz18-Apr-18 8:59 
GeneralRe: C# Javascript in WebBrowser Pin
unfolded19-Apr-18 1:48
unfolded19-Apr-18 1:48 
GeneralRe: C# Javascript in WebBrowser Pin
Gerry Schmitz19-Apr-18 9:08
mveGerry Schmitz19-Apr-18 9:08 
QuestionWebBrowser script communication problem inside C # ActiveX Control Pin
SoulToMind15-Apr-18 22:01
SoulToMind15-Apr-18 22:01 
SuggestionRe: WebBrowser script communication problem inside C # ActiveX Control Pin
Richard MacCutchan15-Apr-18 22:28
mveRichard MacCutchan15-Apr-18 22:28 
GeneralRe: WebBrowser script communication problem inside C # ActiveX Control Pin
SoulToMind15-Apr-18 23:23
SoulToMind15-Apr-18 23:23 
AnswerRe: WebBrowser script communication problem inside C # ActiveX Control Pin
Gerry Schmitz16-Apr-18 7:59
mveGerry Schmitz16-Apr-18 7:59 
QuestionFixing divide by zero exception into a whole new problem Pin
Member 1377871513-Apr-18 13:56
Member 1377871513-Apr-18 13:56 
I'm building a fraction application and I have recently fixed an issue with a divide by zero exception. However after fixing this problem, a whole new one arose, the problem I am having now is that the textbox in which the answer displays always states the denominator as 0 when it is supposed to show the reduced form.

The code for both is below and I appreciate any help or feedback
C#
<pre>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Fractionapp
{
    class Fraction
    {

        private int numerator;
        private int denominator;

        // no parameter constructor.
        public Fraction()
        {
            numerator = 0;
            denominator = 0;
        }

        // two parameter constructor.
        public Fraction(int num, int den)
        {
            numerator = num;
            Denominator = den;
            Reduce();
        }

        // numerator property.
        public int Numerator
        {
            get
            { return numerator; }
            set
            { numerator = value; }
        }

        // denominator property.
        public int Denominator
        {
            get
            {
                return Denominator;
            }
            set
            {
                if (value == 0)
                {
                    throw new ArgumentOutOfRangeException("Denominator", value, "Denominator cannot be zero");

                }
            }
        }

        // reduce method.
        private void Reduce()
        {
            int GCD = 0;
            for (int x = 1; x <= denominator; x++)
            {
                if ((numerator % x == 0) && (denominator % x == 0))
                    GCD = x;
            }
            if (GCD != 0)
            {
                numerator = numerator / GCD;
                denominator = denominator / GCD;
            }
        }

        //// to string method.
        public override string ToString()
        {
            return numerator + "/" + denominator;

        }

    }
    }


C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;


namespace Fractionapp
{

    public partial class Form1 : Form
    {
        //Fraction fr1 = new Fraction();
        //int divisor, numerator, denominator, reducedNumerator, reducedDenominator;
        public Form1()
        {

            InitializeComponent();

        }

        private void btnCalculateFraction_Click(object sender, EventArgs e)
        {


            

            {
                
                Fraction fr2 = new Fractionapp.Fraction(Convert.ToInt32(txtNumerator.Text), Convert.ToInt32(txtDenominator.Text));
                
                txtReduced.Text = "The lowest form of the inputted fraction is: " + fr2.ToString();
                
               
            }
}
}
}

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.