Click here to Skip to main content
15,867,488 members
Home / Discussions / C#
   

C#

 
AnswerRe: How to access remote file directories without sharing. Pin
Chris Quinn16-Dec-13 1:05
Chris Quinn16-Dec-13 1:05 
Questionrectangle screen capture using csharp Pin
Member 1045598615-Dec-13 15:54
professionalMember 1045598615-Dec-13 15:54 
AnswerRe: rectangle screen capture using csharp Pin
Richard MacCutchan15-Dec-13 21:13
mveRichard MacCutchan15-Dec-13 21:13 
AnswerRe: rectangle screen capture using csharp Pin
GuyThiebaut15-Dec-13 22:09
professionalGuyThiebaut15-Dec-13 22:09 
QuestionHow to Get bound of screen without taskbar c# Pin
delphix515-Dec-13 2:47
delphix515-Dec-13 2:47 
AnswerRe: How to Get bound of screen without taskbar c# Pin
BillWoodruff15-Dec-13 3:45
professionalBillWoodruff15-Dec-13 3:45 
GeneralRe: How to Get bound of screen without taskbar c# Pin
delphix515-Dec-13 6:58
delphix515-Dec-13 6:58 
QuestionFraction calculator problem Pin
Member 982953614-Dec-13 18:25
Member 982953614-Dec-13 18:25 
Hello would someone please help me with my program, I'm stuck all day with this thing. The program runs, but I think the problem is a logical error. The fraction 1/4 + 2 1/2 should be equal to 2 3/4 but the program's result is 2 3/8. Another thing is the expression 1/8 + 2 1/2 should be equals to 2 5/8. Please help me how to fix the codes. Thank you very much!

C#
using System;

class FractionDemo
{
    static void Main(string[] args)
    {
        Fraction firstfraction = new Fraction();
        Fraction secondfraction = new Fraction();
        firstfraction.Numerator = 1;
        firstfraction.Denominator = 4;
        secondfraction.Numerator = 1;
        secondfraction.Denominator = 8;
        secondfraction.WholeNumber = 2;
        Fraction add = new Fraction();
        add = firstfraction + secondfraction;

        Console.Write("\n {0}/{1}", firstfraction.Numerator, firstfraction.Denominator);
        Console.WriteLine(" + {0}/{1} = {2}/{3}", secondfraction.Numerator, secondfraction.Denominator, add.Numerator, add.Denominator);
        Console.Write("\n {0}/{1}", firstfraction.Numerator, firstfraction.Denominator);
        Console.WriteLine(" + {0} {1}/{2} = {3} {4}/{5}", secondfraction.WholeNumber, secondfraction.Numerator,secondfraction.WholeNumber, add.WholeNumber, add.Numerator, add.Denominator);
        Console.Write("\n {0}/{1}", firstfraction.Numerator, secondfraction.Denominator);
        Console.WriteLine(" + {0} {1}/{2} = {3} {4}/{5}", secondfraction.WholeNumber, secondfraction.Numerator, secondfraction.WholeNumber, add.WholeNumber, add.Numerator, add.Denominator);
        Console.ReadLine();

    }

    public class Fraction
    {
        private int wholenumber;
        private int numerator;
        private int denominator;

        public int WholeNumber
        {
            get
            {
                return wholenumber;
            }
            set
            {
                wholenumber = value;
            }
        }

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

        public int Denominator
        {
            get
            {
                return denominator;
            }
            set
            {
                denominator = value;
                if (denominator > 0)
                {
                    denominator = value;
                }
                else
                {
                    denominator = 1;
                }
            }
        }

        public Fraction(int wholenumber, int numerator, int denominator)
            : this(numerator, denominator)
        {
            WholeNumber = wholenumber;
        }

        public Fraction(int numerator, int denominator)
        {
            WholeNumber = 0;
            Numerator = numerator;
            Denominator = denominator;
        }

        public Fraction()
        {
            WholeNumber = 0;
            Numerator = 0;
            Denominator = 1;
        }

        public int gcd()
        {
            int x = Numerator;
            int y = Denominator;
            int m;

            if (x > y)
                m = y;
            else
                m = x;

            for (int i = m; i >= 1; i--)
            {
                if (x % i == 0 && y % i == 0)
                {

                    return i;

                }
            }
            return 1;
        }

        public void Reduce()
        {
            int gcdNum = gcd();

            if (gcdNum != 0)
            {
                Numerator = Numerator / gcdNum;
                Denominator = Denominator / gcdNum;
            }
            if (Denominator < 0)
            {
                Denominator = Denominator * -1;
                Numerator = Numerator * -1;
            }
            convertFraction();
        }

        public void convertFraction()
        {
            WholeNumber = Numerator / Denominator;
            Numerator = Numerator % Denominator;
        }

        public static Fraction operator +(Fraction firstfraction, Fraction secondfraction)
        {
            int firstNum = (firstfraction.WholeNumber * firstfraction.Denominator) + firstfraction.Numerator;
            int secondNum = (secondfraction.WholeNumber * secondfraction.Denominator) + secondfraction.Numerator;

            Fraction Result = new Fraction();

            Result.Numerator = firstNum * secondfraction.Denominator + firstfraction.Denominator * secondNum;
            Result.Denominator = firstfraction.Denominator * secondfraction.Denominator;
            Result.Reduce();
            return Result;
        }
    }
}

AnswerRe: Fraction calculator problem Pin
OriginalGriff14-Dec-13 21:54
mveOriginalGriff14-Dec-13 21:54 
AnswerRe: Fraction calculator problem Pin
pzfischer14-Dec-13 22:46
pzfischer14-Dec-13 22:46 
QuestionHow To change mouse cursor Pin
delphix514-Dec-13 10:55
delphix514-Dec-13 10:55 
GeneralRe: How To change mouse cursor Pin
Ron Beyer14-Dec-13 12:00
professionalRon Beyer14-Dec-13 12:00 
GeneralRe: How To change mouse cursor Pin
delphix514-Dec-13 12:14
delphix514-Dec-13 12:14 
AnswerRe: How To change mouse cursor Pin
BillWoodruff14-Dec-13 21:44
professionalBillWoodruff14-Dec-13 21:44 
GeneralRe: How To change mouse cursor Pin
delphix514-Dec-13 22:53
delphix514-Dec-13 22:53 
GeneralRe: How To change mouse cursor Pin
BobJanova16-Dec-13 0:12
BobJanova16-Dec-13 0:12 
QuestionRetrieve all the controls of any window with their types and value Pin
delphix514-Dec-13 5:59
delphix514-Dec-13 5:59 
AnswerRe: Retrieve all the controls of any window with their types and value Pin
Richard MacCutchan14-Dec-13 6:58
mveRichard MacCutchan14-Dec-13 6:58 
GeneralRe: Retrieve all the controls of any window with their types and value Pin
delphix514-Dec-13 7:19
delphix514-Dec-13 7:19 
GeneralRe: Retrieve all the controls of any window with their types and value Pin
Richard MacCutchan14-Dec-13 7:28
mveRichard MacCutchan14-Dec-13 7:28 
GeneralRe: Retrieve all the controls of any window with their types and value Pin
delphix514-Dec-13 8:07
delphix514-Dec-13 8:07 
GeneralRe: Retrieve all the controls of any window with their types and value Pin
Richard MacCutchan14-Dec-13 21:33
mveRichard MacCutchan14-Dec-13 21:33 
QuestionVB Conversion: 'ReadOnly' Error in VB Pin
Sonhospa14-Dec-13 3:48
Sonhospa14-Dec-13 3:48 
AnswerRe: VB Conversion: 'ReadOnly' Error in VB Pin
Ron Beyer14-Dec-13 4:05
professionalRon Beyer14-Dec-13 4:05 
GeneralRe: VB Conversion: 'ReadOnly' Error in VB Pin
Sonhospa14-Dec-13 6:03
Sonhospa14-Dec-13 6:03 

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.