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

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




PostPosted: Wed Apr 23, 2003 8:09 pm   Post subject: put statements

2 questions

i have a code here

code:
put "Please Enter 7 Words:"
put "1." get inwrd1
put "2." get inwrd2
put "3." get inwrd3
put "4." get inwrd4
put "5." get inwrd5
put "6." get inwrd6
put "7." get inwrd7


i want it so that when user input it will come up like the following

1. hello
2. hi
3. bye
etc. . . . . . to 7

2end question is

how can i have it so that user can also input side by suide like this

1. hello, 2. hi, 3. bye etc . . . . . . to 7
Sponsor
Sponsor
Sponsor
sponsor
Dan




PostPosted: Wed Apr 23, 2003 8:17 pm   Post subject: (No subject)

if you put .. at the end of the stamend the next input or output will be at the end of the line insted of the next line.

Ex.

code:

put "put in a num: "..
get num


this whode look like this:

put in a num:
6
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
w0lv3rin3




PostPosted: Wed Apr 23, 2003 8:26 pm   Post subject: (No subject)

how about side by side?
Ancalagon The Black




PostPosted: Wed Apr 23, 2003 8:27 pm   Post subject: (No subject)

code:

var inwrd : array 1 .. 7 of string

put "Please enter 7 words."
put ""

for I: 1 .. 7

  put "Please enter word ", I, ".", " :>" ..
 
  get inwrd (I)

end for

cls

for I: 1 .. 7

  put I,".", inwrd (I)
 
end for


This should do you for now. The only thing I haven't done is to get them all lined up. But with seven words, unless you have a big run window, they'll get cut off. We just started doing arrays so this was good practise for me. In fact, I figured out something while doing this that I need to incorporate into my own program! Very Happy
w0lv3rin3




PostPosted: Wed Apr 23, 2003 8:43 pm   Post subject: (No subject)

i am using that code u told me


i added it into my code, those words will be used in this code

code:

var inwrd, inwrd1, inwrd2, inwrd3, inwrd4, inwrd5, inwrd6, inwrd7 : array 1 .. 7 of string

put
    "The maximum number of letters in the word for Hangman is 10.  When guessing a "
put "letter, please use lowercase letters.  You have 7 guesses."
delay (6)
cls

put "Please enter 7 words."
put ""

for I: 1 .. 7

  put "Please enter word ", I, ".", " :>" ..
 
  get inwrd (I)

end for


code:
% initialization
word (1) := inwrd
word (2) := inwrd
word (3) := inwrd
word (4) := inwrd
word (5) := inwrd
word (6) := inwrd
word (7) := inwrd


i then get error


Assigned value is the wrong type
Ancalagon The Black




PostPosted: Wed Apr 23, 2003 9:14 pm   Post subject: (No subject)

I don't know what you're trying to do at the end here. But first of all, if you don't have word declared as a variable (needs to be an array too) then the program isn't going to like you. It looks like you're doing a hangman program so I think what you need to do is create a list of words, and make the program pick one of them randomly at the beginning of the program. Then when the user inputs seven guesses, you're going to have to make an "if" statement that says for each wrong word, put "wrong", and if the right word is guessed, then put "right!" at the end of the correct word. Something like:

code:


if inwrd (I) = %your random word% then

  put "right!"

else

  put "wrong"

end if



Then you'd probly want to loop the whole thing so that if the player guesses right then the program will start again with a new word. And if the player guesses wrong, then to put game over and exit. I'll have to see if I can get more on this for you later.
jamez




PostPosted: Wed Apr 23, 2003 9:16 pm   Post subject: (No subject)

youre using arrays incorrectly. this tutorial should help http://compsci.ca/bbs/viewtopic.php?t=366
w0lv3rin3




PostPosted: Wed Apr 23, 2003 9:48 pm   Post subject: (No subject)

i am trying to have it so when i type in 7 words, then those words will be then retrieved from

word (1) := inwrd
word (2) := inwrd
word (3) := inwrd
word (4) := inwrd
word (5) := inwrd
word (6) := inwrd
word (7) := inwrd

randomly
Sponsor
Sponsor
Sponsor
sponsor
w0lv3rin3




PostPosted: Wed Apr 23, 2003 10:02 pm   Post subject: (No subject)

this is my code

code:
have to remove code, just in case other class mates dont get it, once done, ill put it back up.
Tony




PostPosted: Wed Apr 23, 2003 10:37 pm   Post subject: (No subject)

inwrd is an array (a 1..7) array. And you're trying to assign a WHOLE array into a single element of it.

Instead you should have

word(1) := inwrd(1)
word(2) := inwrd(2)

If you haven't done so already, read a tutorial on arrays http://compsci.ca/bbs/viewtopic.php?t=366 Hopefully it will explain them better. It also gives some proper examples of using arrays. If you still have problems, dont mind posting (also sujestions if there's something missing in tutorial)
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
w0lv3rin3




PostPosted: Wed Apr 23, 2003 10:43 pm   Post subject: (No subject)

thx, alot
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  [ 11 Posts ]
Jump to:   


Style:  
Search: