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

Username:   Password: 
 RegisterRegister   
 How to make a pogram output TeXt LiKe ThIs
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
zero44




PostPosted: Tue Sep 15, 2009 1:24 pm   Post subject: How to make a pogram output TeXt LiKe ThIs

Im trying to make a program that can get a String of text then check if it is capital or lowercase for each go then change all the characters so the text come out like AbCdEfGhIJkLmNo.
Sponsor
Sponsor
Sponsor
sponsor
BigBear




PostPosted: Tue Sep 15, 2009 1:45 pm   Post subject: RE:How to make a pogram output TeXt LiKe ThIs

In the F10 Help under Turing Language

Keystroke code

how can u tell if a letter is lower case or upper case base on its ordinal value
zero44




PostPosted: Tue Sep 15, 2009 2:32 pm   Post subject: Re: How to make a pogram output TeXt LiKe ThIs

thx for the help but what i need to knw is what i can do to check if a number is odd or even would help i tried this but it doesn't help

code:
% checks if number is odd
var num : int
get num
if num/2 = int then
put "youre number is even"
else
put "youre number is odd"
Insectoid




PostPosted: Tue Sep 15, 2009 2:50 pm   Post subject: RE:How to make a pogram output TeXt LiKe ThIs

Every letter has a numerical value: It's ordinal value. This is it's ASCII code. Capital letters have different values than lower case letters. Iterate over each letter (with a for loop I would suggest) and use the ord() command to determine the value of the letter. From there you can figure it out yourself.
BigBear




PostPosted: Tue Sep 15, 2009 2:52 pm   Post subject: Re: How to make a pogram output TeXt LiKe ThIs

The thing I wanted you to realize was check if it is less than or greater than 96

but to check if it is odd or even

code:
% checks if number is odd
var num : int
get num
if num/2 = int then
put "youre number is even"
else
put "youre number is odd"


First of all there is a few things

code:
if num/2 = int then


num is an integer because when you declared it you put
code:

var num : int


Integer means it can only be whole numbers real numbers can be decimal numbers and whole numbers

for integers instead of using / for divided by you use div

so

code:
if num div 2 = int then


But you cannot say = int because int is a type

You could use


code:
if num div 2 = 0 then
zero44




PostPosted: Tue Sep 15, 2009 2:59 pm   Post subject: Re: How to make a pogram output TeXt LiKe ThIs

every one thx for your help but these method seems to work perfectly

code:
var num : int
var x : int
get num

x = num mod 2
if x = 1 then
put "odd"
else
put "even"
end if
Insectoid




PostPosted: Tue Sep 15, 2009 3:03 pm   Post subject: RE:How to make a pogram output TeXt LiKe ThIs

So...did we answer your first question right or did you just switch questions? Re-reading the thread it looks like this:

You: Hey I need help with this...
Us: Have a look at this...
You: Thanks, but all along I actually needed help with this other thing.
zero44




PostPosted: Tue Sep 15, 2009 3:07 pm   Post subject: Re: How to make a pogram output TeXt LiKe ThIs

ahh no i just forget to mention that i already know how to convert a capital to lowercase by adding 32 in ord but i need to figure out how to tell the computer which one to change and which one not to, so i was gonna do it by odds and evens so all the odd counts in string become caps and all the even become lowercase .... i hope i make sense.....having that said if anyone could help change the script so it comes out as boleen so if even true and if odd false?
Sponsor
Sponsor
Sponsor
sponsor
BigBear




PostPosted: Tue Sep 15, 2009 3:12 pm   Post subject: RE:How to make a pogram output TeXt LiKe ThIs

you are already checking if even or odd so just after you put "even"

have a variable be assigned to true?
zero44




PostPosted: Tue Sep 15, 2009 3:28 pm   Post subject: Re: How to make a pogram output TeXt LiKe ThIs

ok this is what i have so far but it doesn't work need to fix 2 things the boleen and how to read what postion in loop the procces is at

code:
var upperCaseString := "a"
var lowerCaseString := ""
get upperCaseString
var num : int
var t : int
var x : int


procedure check
    x := num mod 2
    if x = 1 then
        var t := 1
    else
        var t := 0
    end if



    for i : 1 .. length (upperCaseString)
        upperCaseString (i) := num
        check
        if t := 1 then
            if ord (upperCaseString (i)) >= 65 and ord (upperCaseString (i)) <= 90 then
                lowerCaseString += upperCaseString (i)
            else
                if
                        ord (upperCaseString (i)) >= 97 and ord (upperCaseString (i)) <= 122 then
                    lowerCaseString += chr (ord (upperCaseString (i)) - 32)

                else
                    if t := 0 then

                        if ord (upperCaseString (i)) >= 65 and ord (upperCaseString (i)) <= 90 then
                            lowerCaseString += chr (ord (upperCaseString (i)) + 32)
                        else
                            if
                                    ord (upperCaseString (i)) >= 97 and ord (upperCaseString (i)) <= 122 then
                                lowerCaseString += upperCaseString (i)
                            end if
                        end if
                    end if
                end if
            end if
        end if
    end for
put lowerCaseString


BigBear i think i understand you i will try and reply
EDIT:
thx BigBear i fixed the boolean problem now i have

code:
var upperCaseString := "a"
var lowerCaseString := ""
get upperCaseString
var num : int
var t : int
var x : int


procedure check
    x := num mod 2
    if x = 1 then
        var t := 1
    else
        var t := 0
    end if



    for i : 1 .. length (upperCaseString)
        upperCaseString (i) := num
        check
        if t := 1 then
            if ord (upperCaseString (i)) >= 65 and ord (upperCaseString (i)) <= 90 then
                lowerCaseString += upperCaseString (i)
            else
                if
                        ord (upperCaseString (i)) >= 97 and ord (upperCaseString (i)) <= 122 then
                    lowerCaseString += chr (ord (upperCaseString (i)) - 32)

                else
                    if t := 0 then

                        if ord (upperCaseString (i)) >= 65 and ord (upperCaseString (i)) <= 90 then
                            lowerCaseString += chr (ord (upperCaseString (i)) + 32)
                        else
                            if
                                    ord (upperCaseString (i)) >= 97 and ord (upperCaseString (i)) <= 122 then
                                lowerCaseString += upperCaseString (i)
                            end if
                        end if
                    end if
                end if
            end if
        end if
    end for
put lowerCaseString
zero44




PostPosted: Tue Sep 15, 2009 4:03 pm   Post subject: Re: How to make a pogram output TeXt LiKe ThIs

sry for double post but my last post was getting too big i have completed the program that i wished to right and it works successfully this is my first ever algorithm and im glad i got the help from you guys so thx
for whoever wants to do something similar or has similar issues here is a script to compare with the old

code:
var upperCaseString := "a"
var lowerCaseString := ""
get upperCaseString
var num : int
var t : boolean := true
var x : int
var a : int


procedure check
    x := num mod 2
    if x = 1 then
        t := true
    else
        t := false
    end if
end check


   

procedure tolower


    if ord (upperCaseString (a)) >= 65 and ord (upperCaseString (a)) <= 90 then
        lowerCaseString += upperCaseString (a)
    else
        if
                ord (upperCaseString (a)) >= 97 and ord (upperCaseString (a)) <= 122 then
            lowerCaseString += chr (ord (upperCaseString (a)) - 32)
            else
            lowerCaseString += upperCaseString (a)
           
        end if
        end if
            end tolower
           
procedure toup


    if ord (upperCaseString (a)) >= 65 and ord (upperCaseString (a)) <= 90 then
        lowerCaseString += chr (ord (upperCaseString (a)) + 32)
    else
        if
                ord (upperCaseString (a)) >= 97 and ord (upperCaseString (a)) <= 122 then
            lowerCaseString += upperCaseString (a)
            else
            lowerCaseString += upperCaseString (a)
       end if
       end if
             end toup





for i : 1 .. length (upperCaseString)

num := i
check
    a := i
    if t = true then
        tolower
    end if
    if t = false then
        toup
    end if


end for
put lowerCaseString
btiffin




PostPosted: Tue Sep 15, 2009 10:39 pm   Post subject: Re: How to make a pogram output TeXt LiKe ThIs

old guy comment
tests for even and odds;

I don't know Turing syntax
code:

if (var AND 1) == 0 then even


The logical AND is usually a lot cheaper than modulus or division.
Cheers
Zren




PostPosted: Tue Sep 15, 2009 11:04 pm   Post subject: Re: How to make a pogram output TeXt LiKe ThIs

btiffin @ Tue Sep 15, 2009 10:39 pm wrote:
old guy comment
tests for even and odds;

I don't know Turing syntax
code:

if (var AND 1) == 0 then even


The logical AND is usually a lot cheaper than modulus or division.
Cheers


Mind explaining how the heck that works? or give a link.
Euphoracle




PostPosted: Tue Sep 15, 2009 11:09 pm   Post subject: RE:How to make a pogram output TeXt LiKe ThIs

Well in binary, if something is odd it _has_ to have 2^0 (1). Therefore, any number represented in binary that has 2^0 as 1 is odd. You can apply this to your current problem.

eg.
7 = 0111 <-- last bit is 2^0 = 1 = odd
6 = 0110 <-- last bit is 2^0 = 0 = even

Rather than using the modulus operator, you can use this knowledge to cheaply check if something is odd.

<var> AND 1 will return 1 if the 2^0 bit of <var> is 1 and 1 is 1 (which it is). If it is zero, it is even because the <var>'s 2^0 bit is not 1.
Zren




PostPosted: Tue Sep 15, 2009 11:40 pm   Post subject: Re: How to make a pogram output TeXt LiKe ThIs

So if you changed 1 to a three, it would also look at 2^1 and compare that, then use an XAND between the two. So it would be true on 0,4,8,...
I see, so it only looks at the digits in the smallest number. Funky. Thanks Euphoracle.
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 2  [ 18 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: