Computer Science Canada

name thing

Author:  Viper [ Thu Sep 08, 2005 8:43 am ]
Post subject:  name thing

A list of names is entered ending with the sentinel name "zzzz". Output each of the names not including the sentinel.
i cant have it not put the sentinel

Author:  Flikerator [ Thu Sep 08, 2005 10:29 am ]
Post subject:  Re: name thing

Viper wrote:
A list of names is entered ending with the sentinel name "zzzz". Output each of the names not including the sentinel.
i cant have it not put the sentinel


All you have to do is is before you put the name, detect the "zzzz".

Depending on how you did it...

exit when name = "zzzz"
put name


(You in Mr.Cs class? Lolz )

Author:  Viper [ Fri Sep 09, 2005 8:04 am ]
Post subject: 

tht dont work bc when they enter the name it puts it on the screen

Author:  Flikerator [ Fri Sep 09, 2005 10:15 am ]
Post subject: 

Mind posting the code? It would be a lot easier to help you then.

Author:  beard0 [ Sun Sep 11, 2005 5:11 pm ]
Post subject: 

code:
View.Set ("noecho")

Author:  Token [ Sun Sep 11, 2005 5:28 pm ]
Post subject: 

I dont think I understand the question, what do you mean by a sentinel? For some odd reason it comes to mind entering passwords when all you get is *** is that what we're trying to do here? I bet I'm completely off.

Author:  beard0 [ Sun Sep 11, 2005 5:37 pm ]
Post subject: 

The sentinel is the name being given to the string "zzzz"
Viper wrote:
...ending with the sentinel name "zzzz".

He need's to output all names except the sentinel, and so far has only managed to "output" every single name, by which I think he actually means that he let turing display them as he input them. What I was saying he should do is use View.Set("noecho") to surpress the display of input, and then actually output only those names that are not "zzzz."

Author:  [Gandalf] [ Sun Sep 11, 2005 5:41 pm ]
Post subject: 

The difficulty in that is that then you don't see what you are typing. There is no way to see what you are typing, and not see when you type zzzz unless you want to ignore all z's or something?

Anyway, since I wanted to...
code:
View.Set ("noecho")
var name : flexible array 1 .. 0 of string
var cnt : int := 0

loop
    cnt += 1
    new name, upper (name) + 1
    get name (cnt)
    exit when name (cnt) = "zzzz"
    put name (cnt)
end loop
put "Finished"


Or a simplified version which doesn't store the names:
code:
View.Set ("noecho")
var name : string

loop
    get name
    exit when name = "zzzz"
    put name
end loop
put "Finished"

Author:  beard0 [ Sun Sep 11, 2005 5:50 pm ]
Post subject: 

Okay, Gandalf

You can see what you type now:

Turing:
var name : flexible array 1 .. 0 of string
loop
    new name, upper (name) + 1
    get name (upper (name))
    exit when name (upper (name)) = "zzzz"
end loop
new name, upper (name) - 1
cls
for i : 1 .. upper (name)
    put name (i)
end for


P.S. Why the cnt?

Author:  [Gandalf] [ Sun Sep 11, 2005 6:05 pm ]
Post subject: 

Oops Embarassed, it's not necessary, you're right.

I thought the problem was that the user shouldn't be able to see even when he is typing the zzzz. This would require the program to probably guess that when z is pressed it shouldn't output the name, which has quite a few problems.

Author:  beard0 [ Sun Sep 11, 2005 6:14 pm ]
Post subject: 

If you wanted to get really fancy, you could use getch, and output anything that could not be "zzzz" (ie, supress "z", but then if the user continues with "a", output "za" and everything that follows).


: