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

Username:   Password: 
 RegisterRegister   
 Primary Divisors Help
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
compstudent




PostPosted: Thu Feb 24, 2011 6:53 pm   Post subject: Primary Divisors Help

Hi
I am making a simple program that finds all the prime divisors of a given number.

Turing:



var test:int
var divs : int
put "Please enter a number"
get test

function prime (a : int) : boolean
    for i : 2 .. a
        if a mod i = 0 then
            result false
        end if
    end for
    result true
end prime

procedure find (test : int)
    for x : 2 .. test
        if test mod x = 0 then
           divs:= test/x
        end if
    end for
    if prime(divs) = true then
    put divs, " Is a prime divisor of ", test
    end if
end find


The problem I am having is with the divs = test/x. It says it is the wrong type but if I change it to a real then it doesn`t work in the prime function in the for loop.

Thanks
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Thu Feb 24, 2011 7:29 pm   Post subject: RE:Primary Divisors Help

Was there supposed to be a question in here?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
compstudent




PostPosted: Thu Feb 24, 2011 7:30 pm   Post subject: Re: Primary Divisors Help

Is there any way to change and Int to a real or vise versa, or any other solution to my problem?

sorry.
Tony




PostPosted: Thu Feb 24, 2011 7:47 pm   Post subject: RE:Primary Divisors Help

you are probably looking for div operator.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
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: