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

Username:   Password: 
 RegisterRegister   
 Help With A Simple ASCII program that I CANT GET TO WORK!!!
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
dmitrip




PostPosted: Mon Mar 05, 2007 4:59 pm   Post subject: Help With A Simple ASCII program that I CANT GET TO WORK!!!

hello

i have an assigment to do for school where i make a program that reads a message a user inputs and outputs back if its a palindrome(reads the same backwards and forwards) or if it isnt a palindrome. The program most inclue

Use ASCII code as much as possible.
The program should ignore punctuation and spaces.
Treat upper and lower case versions of the same letter as the same letter.

here is the code i wrote so far, but for some reason i just cant get it to work. Any help will be very much apprecitead

thank you

[code/]
var input : string
var words : int


% Main Program

% The ASCII for punctuation
chr(32..64)


% asks for the user to input a message and it stores the message into input
put "Please input a message and i will tell you if its a palindrome"
get input

% stores the length of the message in the variable words
words := length(input)

% loop for 'a' as for chr a - z and loop for'A' as for chr A-Z
for a : 65..90
for A : 97..122


% sets chr a to equal to chr A ...
if chr(a) = chr(A) then


end if
end for
end for

% loop that coutns letter 1 to the end of the word and from the end of the word to letter 1
for decreasing second_letter :length(input)..1
for first_letter : 1..length(input)



% if structure that checks that all letters equal each other
if input(first_letter) = input(second_letter) then


% outputs the message is a palindrome if the if structure is true
put "The message is a palindrome"

else

% outputs the message is not a palindrome if the if structure is false
put "The message is not a palindrome"


end if


end for
end for

% End of Main Program
[code/]
Sponsor
Sponsor
Sponsor
sponsor
Clayton




PostPosted: Mon Mar 05, 2007 6:19 pm   Post subject: Re: Help With A Simple ASCII program that I CANT GET TO WORK!!!

Have you tried running the code yet? I don't think you have, as it doesn't work. Also, your first nested for loop, it just doesn't make sense.... You don't do anything within the condition that you have set, so I'm not sure what you were thinking. The best idea I could give to you is just take your string that you get, and turn it to lowercase using ASCII character numbers, then evaluate the actual characters from there.
syntax_error




PostPosted: Wed Mar 07, 2007 11:34 pm   Post subject: Re: Help With A Simple ASCII program that I CANT GET TO WORK!!!

if i an not mistake i think there is an easier way to do this...............
btw please correct meif i make no sence............
okey here is how i would slove this problem. I would simply use arrys such as......... the users first entry is stroyed into a array then use for loops to simplely add 1 evertime the char 'a' is there and soo on............now that you have a array of the first input values u do the same prosses for then next input and cross check the values and if they match the its palindrome if not it ant.......
hope this helps......btw this is jsut a thought at 11: 33 so if it dont make sence srry. Wink
syntax_error




PostPosted: Wed Mar 07, 2007 11:37 pm   Post subject: Re: Help With A Simple ASCII program that I CANT GET TO WORK!!!

sorry for double posting...............
btw wasn't this like the second last question for the CCC junior??
LindenRulz




PostPosted: Thu Mar 08, 2007 3:36 pm   Post subject: Re: Help With A Simple ASCII program that I CANT GET TO WORK!!!

I have had to do a similar assignment. I had to verify if a 3 didget number was a palindrome and I used div and mod. Here is my program:
code:

var threedignum : int
put "Enter a 3 didget number " ..
get threedignum
if threedignum div 100 = threedignum mod 10 then
put "This number is a palindrome"
else
put "This is not a palindrome"
end if

Hope this helps! Smile Smile Smile
d2bb




PostPosted: Fri Mar 09, 2007 9:17 am   Post subject: RE:Help With A Simple ASCII program that I CANT GET TO WORK!!!

shoudnt give ppl the answer to there home work Sad
syntax_error




PostPosted: Fri Mar 09, 2007 7:16 pm   Post subject: Re: Help With A Simple ASCII program that I CANT GET TO WORK!!!

Thats not the answer.............its an example..............and a idea...becuase its with numbers and strings are different Exclamation
jrblast




PostPosted: Fri Mar 16, 2007 12:18 am   Post subject: Re: Help With A Simple ASCII program that I CANT GET TO WORK!!!

syntax_error @ Wed Mar 07, 2007 11:37 pm wrote:
sorry for double posting...............
btw wasn't this like the second last question for the CCC junior??

No, that one asked the user for 2 inputs and returned if they were ACRONYMS, similar idea though.

If its a palindrome then the first letter and last must be the same right? and the second and second last? and third and third last? So why dont we go through the word and if the first letter equals the last letter than get rid of both ( variable := variable (2 .. * - 1) ), do that in a seperate variable, and the the second and second last letters will be the first and the last, so repeat. then if in the end the variable is nothing, ie variable = "", then its a palindrome, otherwise...Its not...

If your having trouble with the other part then you can just loop through the variale, char by char and if its a letter add it as a lowe case to another variable... Or you could just eliminate that letter from that variable, but that may cause problems. Whichevers easier is probably a better choice in this situation.
Sponsor
Sponsor
Sponsor
sponsor
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  [ 8 Posts ]
Jump to:   


Style:  
Search: