
-----------------------------------
Brutus
Mon Jan 17, 2005 12:30 pm

Putting a fraction into lowest terms
-----------------------------------
Hey everyone, I'm new here so I'm not really sure how to post, but here goes. I am making a program that is supposed to calculate slpoe of a line segment. I can get the slope, but the problem is getting it into lowest terms. Any one know how I would achieve this?  here is my program so far:


%Analytic Geometry program opening
var coor1 : int
coor1 := 0
var coor2 : int
coor2 := 0
var coor3 : int
coor3 := 0
var coor4 : int
coor4 := 0
var answer : int

put "Welcome to the Analytic Geometry program. This program is designed to calculate the slope, length and equasion of a line."

delay (8000)
cls
loop

    put "Please enter the 'x' co-ordinate for the first endpoint of your line."
    get coor1
    put "Now the 'y' co-ordinate for the first endpoint of your line."
    get coor2
    put "Ok thanks. Now I need the 'x' co-ordinate for the second endpoint."
    get coor3
    put "Got it. Now the 'y' co-ordinate for the second endpoint"
    get coor4
    delay (5000)
    cls

    put "Alright, I've got it all worked out now, so go ahead and choose an option."
    loop
        put "For the slope of you line, press 1."
        put "For the length of your line, press 2."
        put "For the equasion of your line, press 3."
        put "To re-enter your numbers, press 4."
        get answer
        exit when answer = 4
        if answer = 1 then
            put "The slope of your line is ", coor2 - coor4, "/", coor1 - coor3, "."
        elsif answer = 2 then
            put "The length of your line is  "
        elsif answer = 3 then
            put "The equasion of your line is "
        else
            put "Hey! Come on now buddy. I was nice enough to bail you out by doing all the    hard stuff for you, so do me a favour and choose one of the options I gave you."
        end if
        delay (10000)
        cls
    end loop
end loop


thanks in advance to whoever helps me

-----------------------------------
Tony
Mon Jan 17, 2005 1:27 pm


-----------------------------------
to get a fraction in its lowest term, you find the factors of both nominator and denominator and divide them both by their common factors.

-----------------------------------
Bacchus
Mon Jan 17, 2005 3:34 pm


-----------------------------------
i sugest using mod to see the largest common denometer
var num1,num2,highest:int
num1:=6
num2:=9
if num1 abs (run) then
for i: decreasing abs run .. 2
if rise mod i = 0 and run mod i - 0 then 
rise:= rise/i
run:= run/i
end if
end for
else for i: decreasing abs (rise) .. 2
if run mod i = 0 and rise mod i = 0 then
rise := rise/i
run:= run/i
end if
end for
end if
end lowestterms


Problem is now, that it won't run with the "i" and decreasing things. Any idea why?

-----------------------------------
scottyrush13
Wed Jan 19, 2005 12:32 pm


-----------------------------------
i think the other i's inside the for statement need to be in brackets

-----------------------------------
Bacchus
Wed Jan 19, 2005 3:44 pm


-----------------------------------
no but the decreasing part has to come b4 the i ex) for decreasing i:5..1

-----------------------------------
Brutus
Thu Jan 20, 2005 12:03 pm


-----------------------------------
Thanks scotty and Bacchus. Hahaha, ya, the decreasing comes before the "i". Also, the "/" had to be changed to div. I hate it when the hardest answer to find is the simple one.... Anyways, thanks again.

-----------------------------------
phuong
Tue May 31, 2005 11:24 am


-----------------------------------
if you're still interested... (don't think so but anyway)
here's a program that CAN reduce fractions. check it out.
here's the datafile for it too.

-----------------------------------
[Gandalf]
Wed Jun 01, 2005 10:10 am


-----------------------------------
Well, I don't know - this was quite a while ago.  I would just post something in the source code section - a new topic.

Also, when you submit something, include all the files neccessary.
