Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,622 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,024 people online right now. Registration is fast and FREE... Join Now!




Fraction Calculator C++

 
Reply to this topicStart new topic

Fraction Calculator C++

spoc2403
post 2 Sep, 2005 - 01:34 PM
Post #1


New D.I.C Head

*
Joined: 9 Aug, 2005
Posts: 8

I got my calculator gui working and it can work with decimals but i need i to work with fractions only or both. I made a new button for the fractions which is x\y because \ is allready taken by divide. If anyone could help me make this calculator do fractions that would be great. thanks


Attached File(s)
Attached File  caltu.rar ( 1.59mb ) Number of downloads: 340
User is offlineProfile CardPM

Go to the top of the page

Dark_Nexus
post 2 Sep, 2005 - 11:06 PM
Post #2


or something bad...real bad.

Group Icon
Joined: 2 May, 2004
Posts: 1,309



Thanked 2 times

Dream Kudos: 625
My Contributions


yah know, fractions and division go hand in hand, which is why they use the / sign

3/4 = 0.75

knowing this you could simply have the user enter fractions as "3/5" and have the program take it explicitly, and peform the division.

but, probably already knowing this, your best bet would be to store the numerator and the denominator as two seperate variables, and use the '\' as the dilimeter for input.

This post has been edited by Dark_Nexus: 2 Sep, 2005 - 11:13 PM
User is offlineProfile CardPM

Go to the top of the page

born2c0de
post 3 Sep, 2005 - 09:22 AM
Post #3


printf("I'm a %XR",195936478);

Group Icon
Joined: 26 Nov, 2004
Posts: 3,905



Thanked 34 times

Dream Kudos: 2800

Expert In: 80x86 Assembly, C/C++, VB6, VB.NET, C#, J2SE, Win32 API, Reversing

My Contributions


There's a code snippet using a Class to use Fractions.
Try and see if that helps.
HERE

Besides, if you want to do something in particular with the fractions, let us know. That way it's easier to help.

This post has been edited by born2c0de: 3 Sep, 2005 - 09:23 AM
User is offlineProfile CardPM

Go to the top of the page

bcoopey
post 21 Sep, 2005 - 10:08 AM
Post #4


New D.I.C Head

*
Joined: 21 Sep, 2005
Posts: 1


My Contributions


what code would you put to make the program simplify the fraction??
User is offlineProfile CardPM

Go to the top of the page

Dark_Nexus
post 21 Sep, 2005 - 12:27 PM
Post #5


or something bad...real bad.

Group Icon
Joined: 2 May, 2004
Posts: 1,309



Thanked 2 times

Dream Kudos: 625
My Contributions


well if the numerator can be divided into the denominator with 0 remainder, it can be simplified

for instance if you were presented with the input "2/4"



CODE
(2 % 4) % 4


this would equate to 0, meaning that they can be divided be each other, or in other words they can be simplified.

CODE
(numerator % denominator) % denominator


knowing that the fraction needs to be simplified you could simplifgy it the same way with %(modulus)

This post has been edited by Dark_Nexus: 21 Sep, 2005 - 02:23 PM
User is offlineProfile CardPM

Go to the top of the page

born2c0de
post 25 Sep, 2005 - 09:44 AM
Post #6


printf("I'm a %XR",195936478);

Group Icon
Joined: 26 Nov, 2004
Posts: 3,905



Thanked 34 times

Dream Kudos: 2800

Expert In: 80x86 Assembly, C/C++, VB6, VB.NET, C#, J2SE, Win32 API, Reversing

My Contributions


QUOTE(bcoopey @ Sep 22 2005, 12:35 AM)
what code would you put to make the program simplify the fraction??

Relax...read the code snippet carefully.
It simplifies fractions...always...
User is offlineProfile CardPM

Go to the top of the page

blackbelttcon
post 13 Jan, 2008 - 02:01 PM
Post #7


New D.I.C Head

*
Joined: 18 Jul, 2007
Posts: 3


My Contributions


hey i am trying to write a code that multiplies a variable by a fraction here is what i have tryed,


1/4* r

(1%4)*r

1/4*2

and a lot more, none of these work, i get 0 as the answer.

what should i use
User is offlineProfile CardPM

Go to the top of the page

Amadeus
post 13 Jan, 2008 - 02:28 PM
Post #8


g++ -o drink whiskey.cpp

Group Icon
Joined: 12 Jul, 2002
Posts: 12,176



Thanked 33 times

Dream Kudos: 25
My Contributions


What data type is r?
User is offlineProfile CardPM

Go to the top of the page

Bench
post 13 Jan, 2008 - 03:57 PM
Post #9


D.I.C Addict

Group Icon
Joined: 20 Aug, 2007
Posts: 602



Thanked 10 times

Dream Kudos: 150

Expert In: C/C++

My Contributions


1/4 will always be zero. If you're attempting to multiply numerator/denominator by another number, then you ought to multiply the numerator on its own, then use the denominator to work out your new number as a fraction

This post has been edited by Bench: 13 Jan, 2008 - 04:00 PM
User is offlineProfile CardPM

Go to the top of the page

blackbelttcon
post 15 Jan, 2008 - 12:55 PM
Post #10


New D.I.C Head

*
Joined: 18 Jul, 2007
Posts: 3


My Contributions


QUOTE(Bench @ 13 Jan, 2008 - 04:57 PM) *

1/4 will always be zero. If you're attempting to multiply numerator/denominator by another number, then you ought to multiply the numerator on its own, then use the denominator to work out your new number as a fraction





r is the variable for radius, alright thanx, ill try that.
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/23/08 03:21AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month