Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Simplifying Fractions (and sign help)
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Fifa4ever




PostPosted: Thu Nov 18, 2010 7:11 pm   Post subject: Simplifying Fractions (and sign help)

What is it you are trying to achieve?
A program that adds, multiplys, subtracts, and divides fractions into simplest form.


What is the problem you are having?
Cant and dont know how to simplify.
ALSO having a problem when adding it doesnt show (+) sign also with every other (multiply,dividing,and subtraction) sign



Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)

Turing:


%Variables
var data : string (1) % keys and input
var numTop, numBottom, num2Top, num2Bottom : int
var addTop, addBottom : int
var subTop, subBottom : int
var mulTop, mulBottom : int
var divTop, divBottom : int

% Setscreen and Grey color Background +  Font
setscreen ("graphics:640;480, ")
colorback (11)
color (1)
cls




procedure showfraction (f, b, x : int)
    if length (intstr (f)) > length (intstr (b)) then
        locate (8, x)
        put f
        locate (9, x)
        put repeat ("-", length (intstr (f)))
        locate (10, x)
        put b
    else

        locate (8, x)
        put f
        locate (9, x)
        put repeat ("-", length (intstr (b)))
        locate (10, x)
        put b
    end if
end showfraction




%Greetings
put "Hello this program will solve fractions"
% Opening Menu
put " "
put " "
put " "
put "Press (1) to input data and Start Program!!"
put " "
put " "
put " "
put " "
put " "
put " "
put " "
put "Press (6) to exit at any time during the program"
put " "
put " "
put " "
put " "
put " "
put " "
put " "
put " "
put " "
put " "
put " "
put " "
put "Created by :"
loop
    if hasch then             %Input
        getch (data)
        if data = chr (49) then
            cls
            % Now getting the 2 fractions from user
            put "Enter the first fraction (enter Numerator, space, enter denominator) " ..
            get numTop, numBottom
            put "Enter the second fraction (enter Numerator, space, enter denominator) " ..
            get num2Top, num2Bottom
            cls
            put "Your Fractions :"
            showfraction (numTop, numBottom, 30)
            showfraction (num2Top, num2Bottom, 37)


            put "Press (2) to add your fractions"
            put "Press (3) to subtract your fractions"
            put "Press (4) to multiply your fractions"
            put "Press (5) to divide your fractions"



            %Addition
        elsif data = chr (50) then
            cls
            put "Addition"

            % Shows the user their 2 fractions with a '+ sign' between the them
            showfraction (numTop, numBottom, 30)
            put "+"
            showfraction (num2Top, num2Bottom, 37)

            % This will add the 2 fractions and output answer
            addTop := (numTop * num2Bottom) + (num2Top * numBottom)
            addBottom := (numBottom * num2Bottom)
            showfraction (addTop, addBottom, 45)

            put "Press (3) to subtract your fractions"
            put "Press (4) to multiply your fractions"
            put "Press (5) to divide your fractions"
            put "Or Press(1) to try another fraction"
            put "Press(6) to exit"


            % Subtraction
        elsif data = chr (51) then
            cls
            put "Subtraction"
            % Shows the user their 2 fractions with a '- sign' between the them
            showfraction (numTop, numBottom, 30)
            put "-"
            showfraction (num2Top, num2Bottom, 37)
            % This will subtract the 2 fractions and output answer
            subTop := (numTop * num2Bottom) - (num2Top * numBottom)
            subBottom := (numBottom * num2Bottom)
            showfraction (subTop, subBottom, 45)

            put "Press (2) to add your fractions"
            put "Press (4) to multiply your fractions"
            put "Press (5) to divide your fractions"
            put "Or Press(1) to try another fraction"
            put "Press(6) to exit"


            % Multiplication
        elsif data = chr (52) then
            cls
            put "Multiplication"
            % Shows the user their 2 fractions with a '* sign' between the them
            showfraction (numTop, numBottom, 30)
            put "*"
            showfraction (num2Top, num2Bottom, 37)
            % This will multiply the 2 fractions and output answer
            mulTop := (numTop * num2Top)
            mulBottom := (numBottom * num2Bottom)
            showfraction (mulTop, mulBottom, 45)

            put "Press (2) to add your fractions"
            put "Press (3) to subtract your fractions"
            put "Press (5) to divide your fractions"
            put "Or Press(1) to try another fraction"
            put "Press(6) to exit"


            %Division
        elsif data = chr (53) then
            cls
            put "Division"
            % Shows the user their 2 fractions with a '/ sign' between the them
            showfraction (numTop, numBottom, 30)
            put "/"
            showfraction (num2Top, num2Bottom, 37)
            % This will divide the 2 fractions and output answer
            divTop := (numTop * num2Bottom)
            divBottom := (numBottom * num2Top)
            put "Press (2) to add your fractions"
            put "Press (3) to subtract your fractions"
            put "Press (4) to multiply your fractions"
            put "Or Press(1) to try another fraction"
            put "Press(6) to exit"
            % Exits
        elsif data = chr (54) then
            cls
            put " BYE :D!!!"
            exit
        end if
    end if

end loop



Please specify what version of Turing you are using
4.1.1
Sponsor
Sponsor
Sponsor
sponsor
TerranceN




PostPosted: Thu Nov 18, 2010 7:44 pm   Post subject: RE:Simplifying Fractions (and sign help)

Someone asked a similar question today, cause I remember someone linking to this wikipedia article, which is exactly what you need to find to simplify your fraction.

The operation symbols aren't showing up because you have something being drawn on top of them (the line that says "Press (2) to add your fractions"). Use a locate command to tell Turing exactly where to draw them.

Also be careful if the user enters a first fraction which has many digits in it, as your program might draw them over top one another.
Fifa4ever




PostPosted: Thu Nov 18, 2010 9:01 pm   Post subject: Re: Simplifying Fractions (and sign help)

Thanks for your help. Locate worked but took forever and thanks for the site i guess i should have looked to see if there were other users with this problem Very Happy
TerranceN




PostPosted: Thu Nov 18, 2010 9:09 pm   Post subject: RE:Simplifying Fractions (and sign help)

I wouldn't worry about asking the same question as someone else if it is fairly specific. I only mentioned it because I wanted to give whoever posted that link first credit.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: