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

Username:   Password: 
 RegisterRegister   
 Long sentences using string variables being cut off
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
14fenix




PostPosted: Sun Sep 28, 2003 11:03 pm   Post subject: Long sentences using string variables being cut off

For a lame school assignment I have to ask the user to input answers to 20 questions. The answers are strings.. At the end, I output a story using the answers to fill in gaps kind of like a mad libs thing... There are two problems im getting;

1) Strings need to be one word otherwise any extra words will be cut off. I overcame this problem by asking the user for quotes but is there a neater, simpler way??

2) On the output screen, words near the end of the line are being cut off and broken into two. I tried messing around with the spacing in my put statementsbut I realized that the answers may vary in length meaning that it wont make a difference. Anyways to fix this??

Here is my code. Pretty basic stuff (used arrays thats advanced lol)

code:
% 20 Questions ~ Paul Bialo ~ ICS3M %
setscreen ("graphics")

% Variables %
var w1, count : int
var answer : array 1 .. 20 of string (50)
var name : string
var FontID : int := Font.New ("PL arsic:30")
var FontID1 : int := Font.New ("impact:50:italic, bold, underline")
var FontID2 : int := Font.New ("arial black:50: bold, italic")
var FontID3 : int := Font.New ("arial black:50: bold")

% Window modifications %
w1 := Window.Open ("title: 20 Questions by Paul Bialo , screen: max,max;position:0,0")

% Introduction, black background "Welcome to 20 Questions by Paul Bialo" using different texts %
colorback (black)
cls
delay (1000)
Font.Draw ("Welcome to 20 Questions", 140, maxy div 2, FontID1, blue)
delay (1000)
cls
Font.Draw ("By...", 140, 350, FontID1, blue)
delay (1000)
cls
Font.Draw ("P", 250, maxy div 2, FontID2, red)
delay (200)
Font.Draw ("A", 290, maxy div 2, FontID2, white)
delay (200)
Font.Draw ("U", 340, maxy div 2, FontID2, red)
delay (200)
Font.Draw ("L", 390, maxy div 2, FontID2, white)
delay (200)
Font.Draw ("B", 480, maxy div 2, FontID2, red)
delay (200)
Font.Draw ("I", 530, maxy div 2, FontID2, white)
delay (200)
Font.Draw ("A", 555, maxy div 2, FontID2, red)
delay (200)
Font.Draw ("L", 605, maxy div 2, FontID2, white)
delay (200)
Font.Draw ("O", 645, maxy div 2, FontID2, red)
delay (1500)
cls

% Ask for name %
colorback (black)
cls
color (white)
put "After answering the 20 questions, you will be told a story thats uses the answers that you input."
put "But before we begin, I would like to know your first name."
put " "
get name
put "For answers that require to use multiple words, please use quotes around you answer."
delay (3000)
cls

% Series of questions %

% Question 1 %
Font.Draw ("Question #1", maxx div 4, maxy div 2, FontID2, red)
delay (1000)
cls
put "What time did you wake up (use quotes for multiple words)?"
get answer (1)
cls

% Question 2 %
Font.Draw ("Question #2", maxx div 4, maxy div 2, FontID2, red)
delay (1000)
cls
put "What is your lucky number"
get answer (2)
cls

% Question 3 %
Font.Draw ("Question #3", maxx div 4, maxy div 2, FontID2, red)
delay (1000)
cls
put "What is your favourite type of food (use quotes for multiple words)?"
get answer (3)
cls

% Question 4 %
Font.Draw ("Question #4", maxx div 4, maxy div 2, FontID2, red)
delay (1000)
cls
put "What is the name of a school in your city (use quotes for multiple words)?"
get answer (4)
cls

% Question 5 %
Font.Draw ("Question #5", maxx div 4, maxy div 2, FontID2, red)
delay (1000)
cls
put "Who is your best friend?"
get answer (5)
cls

% Question 6 %
Font.Draw ("Question #6", maxx div 4, maxy div 2, FontID2, red)
delay (1000)
cls
put "What is the name of one of your other friends?"
get answer (6)
cls

% Question 7 %
Font.Draw ("Question #7", maxx div 4, maxy div 2, FontID2, red)
delay (1000)
cls
put "How old are you?"
get answer (7)
cls

% Question 8 %
Font.Draw ("Question #8", maxx div 4, maxy div 2, FontID2, red)
delay (1000)
cls
put "What is your least favourite class (use quotes for multiple words)?"
get answer (8)
cls

% Question 9 %
Font.Draw ("Question #9", maxx div 4, maxy div 2, FontID2, red)
delay (1000)
cls
put "What is the name of your favourite computer game (use quotes for multiple words)?"
get answer (9)
cls

% Question 10 %
Font.Draw ("Question #10", maxx div 4, maxy div 2, FontID2, red)
delay (1000)
cls
put "What kind of pet do you have or would you like to have?"
get answer (10)
cls

Font.Draw ("Halfway there!", maxx div 4, maxy div 2, FontID2, red)
delay (1500)
cls

% Question 11 %
Font.Draw ("Question #11", maxx div 4, maxy div 2, FontID2, red)
delay (1000)
cls
put "Name a politician you really hate (use quotes for multiple words)"
get answer (11)
cls

% Question 12 %
Font.Draw ("Question #12", maxx div 4, maxy div 2, FontID2, red)
delay (1000)
cls
put "What is an object that you can find in a classrom?"
get answer (12)
cls

% Question 13 %
Font.Draw ("Question #13", maxx div 4, maxy div 2, FontID2, red)
delay (1000)
cls
put "What is the name of a novel that you really dislike (use quotes for multiple words)?"
get answer (13)
cls

% Question 14 %
Font.Draw ("Question #14", maxx div 4, maxy div 2, FontID2, red)
delay (1000)
cls
put "What is your favourite musical instrument (use quotes for multiple words)?"
get answer (14)
cls

% Question 15 %
Font.Draw ("Question #15", maxx div 4, maxy div 2, FontID2, red)
delay (1000)
cls
put "What sport do you like the most?"
get answer (15)
cls

% Question 16 %
Font.Draw ("Question #16", maxx div 4, maxy div 2, FontID2, red)
delay (1000)
cls
put "Name something that makes you squirm."
get answer (16)
cls

% Question 17 %
Font.Draw ("Question #17", maxx div 4, maxy div 2, FontID2, red)
delay (1000)
cls
put "What subject do you find the most boring?"
get answer (17)
cls

% Question 18 %
Font.Draw ("Question #18", maxx div 4, maxy div 2, FontID2, red)
delay (1000)
cls
put "What fruit do you absolutely hate?"
get answer (18)
cls

% Question 19 %
Font.Draw ("Question #19", maxx div 4, maxy div 2, FontID2, red)
delay (1000)
cls
put "What is your favourite television show (use quotes for multiple words)?"
get answer (19)
cls

% Question 20 %
Font.Draw ("Question #20", maxx div 4, maxy div 2, FontID2, red)
delay (1000)
cls
put "Name your favourite 'Saved by the Bell' Character (use quotes for multiple words)?"
get answer (20)
cls

% The story is now told %
Font.Draw ("Finally! We're done.", maxx div 4, maxy div 2, FontID2, white)
delay (1500)
cls

Font.Draw ("A Regular Day at School", maxx div 6, maxy - 100, FontID1, white)
delay (1500)

put "   ", answer (1), " in the morning is way too early to wake up I thought to myself." ..
put " As usual, I took a ", answer (2), " minute shower which is my regular custom in the morning." ..
put " It is usually followed up by eating a quick breakfast. Today my mother had warmed up some ", answer (3) ..
put " from last night's supper. I finished drinking my ", answer (18), " juice and was out the door."
put " "
put "   Soon I was on the school bus on the way to ", answer (4), ". Although, I really hate school, " ..
put "I'm always glad to see my best friends "
put answer (5), " and ", answer (6), "As I heard the " ..
put "bell go I realized I was gooing to be late for ", answer (8), " class." ..
put "My teacher Mr. Ratliff yelled at me for " ..
put "for being late. I think his lecture lasted for about " ..
put answer (7), " minutes. He then asked me for my assignment from the night before. When I realized" ..
put "  realized that I had not finished it, I told him that my ", answer (10), " ate it." ..
put " He got so angry that he threw a ", answer (12), " which just missed my head."
put " "
put "   The next two classes were bearable. I managed to sleep through ", answer (17), " and I " ..
put "played ", answer (9), " during Computer Science. At lunch I had some leftover ", answer (3) ..
put " from breakfast and then I headed to the music room." ..
put " My principal whom we call ", answer (11), " because  " ..
put "they look identical almost sent me home for playing my ", answer (14), " too loud."
put " "
put "   At ", answer (15), " practice that afternoon, some idiot thought it would be " ..
put "funny to put ", answer (16), " in my water bottle. I later found " ..
put " out that it was ", answer (20), ". What a loser." ..
put " After watching an enertaining episode of ", answer (19) ..
put " at home that night I decided it was time to start my report on ", answer (13), " which " ..
put "was due the next day. Pretty interesting day."


I erased some stuff to make it shorter, just small effects. And dont laugh at the gay story, ive been lacking sleep all weekend and having a kegger last night doesnt help. THanx for any advice
Sponsor
Sponsor
Sponsor
sponsor
Mazer




PostPosted: Mon Sep 29, 2003 7:36 am   Post subject: (No subject)

for the using quotes when entering strings thing, just use:
code:

get answer(1):*

and that will put everything into the array including spaces
Tony




PostPosted: Mon Sep 29, 2003 8:49 am   Post subject: (No subject)

I dont remember how good Turing is with word wrapping Confused

I suppose you could overcome that by writing your own word wrap function and feeding it text from a file + answer array.

Would be something like
code:

function wordWarp(word:string)
if length(word)+lineFilled > maxcol then %if word is to be split

put "" %go to new line
lineFilled=0 %reset counter

else %otherwise
put word.. %output word .. will keep next word on same line

end if

end wordWarp


Now you feel words one at a time into this function and it will wordWarp the text for you.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
PaddyLong




PostPosted: Mon Sep 29, 2003 10:10 am   Post subject: (No subject)

I think turing just wraps letters... so it splits words up hehe

also, you should use a function for asking a question... something that takes in which question # it is and the question....

function question (number : int, question : string)
font.draw question number blah blah
font.draw question blah blah
get answer (number)
end question

too lazy to look back in your post and see exact font.draw command, but it looks like they're all the same, so a function would work here
Blade




PostPosted: Mon Sep 29, 2003 1:46 pm   Post subject: (No subject)

:: whisper :: could a mod please put that into a text file?
14fenix




PostPosted: Mon Sep 29, 2003 8:50 pm   Post subject: (No subject)

Well thanx a lot for all the help.

Hey mods, how about some bits for my first program that runs for more than 20 seconds?? Consider it encouragement for me to continue writing stuff Rolling Eyes
krishon




PostPosted: Tue Sep 30, 2003 5:53 pm   Post subject: (No subject)

got enough bits now, lol
14fenix




PostPosted: Tue Sep 30, 2003 7:31 pm   Post subject: (No subject)

Heheh, you rule Krishon!! Thanx for all the help guys. My actual program got extended quite a bit and it turned out looking decent.
Mazer




PostPosted: Tue Sep 30, 2003 7:55 pm   Post subject: (No subject)

hey sherlock, what about the guy who has 0 bits all of the sudden?

PS: you're welcome.
krishon




PostPosted: Wed Oct 01, 2003 7:26 pm   Post subject: (No subject)

yah...it probably is mazer...i didn't really give u ne...just commenting after a huge rise in bits.....mazer's usually very generous with his bits...partly cuz he dusn't care
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  [ 10 Posts ]
Jump to:   


Style:  
Search: