Click here to Skip to main content
15,887,302 members
Home / Discussions / C#
   

C#

 
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();
                
               
            }
}
}
}

AnswerRe: Fixing divide by zero exception into a whole new problem Pin
Luc Pattyn13-Apr-18 15:26
sitebuilderLuc Pattyn13-Apr-18 15:26 
GeneralRe: Fixing divide by zero exception into a whole new problem Pin
Member 1377871513-Apr-18 16:38
Member 1377871513-Apr-18 16:38 
GeneralRe: Fixing divide by zero exception into a whole new problem Pin
Luc Pattyn13-Apr-18 16:46
sitebuilderLuc Pattyn13-Apr-18 16:46 
GeneralRe: Fixing divide by zero exception into a whole new problem Pin
Member 1377871513-Apr-18 17:02
Member 1377871513-Apr-18 17:02 
SuggestionRe: Fixing divide by zero exception into a whole new problem Pin
Richard Deeming19-Apr-18 1:39
mveRichard Deeming19-Apr-18 1:39 
QuestionNull values from sql server database are displayed #VALUE! in Excel Pin
Gtari Abir13-Apr-18 6:09
Gtari Abir13-Apr-18 6:09 
AnswerRe: Null values from sql server database are displayed #VALUE! in Excel Pin
OriginalGriff13-Apr-18 6:31
mveOriginalGriff13-Apr-18 6:31 
AnswerRe: Null values from sql server database are displayed #VALUE! in Excel Pin
mecoder8915-Apr-18 22:01
mecoder8915-Apr-18 22:01 
AnswerRe: Null values from sql server database are displayed #VALUE! in Excel Pin
Gtari Abir16-Apr-18 0:27
Gtari Abir16-Apr-18 0:27 
QuestionNeed help with Functions, ASAP! Pin
Member 1377783813-Apr-18 1:30
Member 1377783813-Apr-18 1:30 
AnswerRe: Need help with Functions, ASAP! Pin
Keviniano Gayo13-Apr-18 2:01
Keviniano Gayo13-Apr-18 2:01 
AnswerRe: Need help with Functions, ASAP! Pin
#realJSOP13-Apr-18 4:14
mve#realJSOP13-Apr-18 4:14 
AnswerRe: Need help with Functions, ASAP! Pin
#realJSOP13-Apr-18 6:23
mve#realJSOP13-Apr-18 6:23 
AnswerRe: Need help with Functions, ASAP! Pin
Eddy Vluggen13-Apr-18 6:45
professionalEddy Vluggen13-Apr-18 6:45 
AnswerRe: Need help with Functions, ASAP! Pin
Gerry Schmitz13-Apr-18 7:15
mveGerry Schmitz13-Apr-18 7:15 
AnswerRe: Need help with Functions, ASAP! Pin
#realJSOP13-Apr-18 7:49
mve#realJSOP13-Apr-18 7:49 
AnswerRe: Need help with Functions, ASAP! Pin
BillWoodruff13-Apr-18 7:51
professionalBillWoodruff13-Apr-18 7:51 

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.