Computer Science Canada

How To Center An Input

Author:  Da_Big_Ticket [ Fri Oct 07, 2005 12:21 pm ]
Post subject:  How To Center An Input

Ok for my turing assignment The user must input a word for the program to determine its middle letter(s). When inputting you must locate the cursor to a specific point on the screen but this does not necessarily center the input. How can I make it so that turing will center the characters as they are inputted, to make the program work nicely?

Thanks

Author:  codemage [ Fri Oct 07, 2005 12:30 pm ]
Post subject: 

I'll assume you're not supposed to use any of the centering functions floating about for text.

So... *semi-hint*

You can find the middle of a string by dividing it in half.

Using this information, you should be able to centre the string on screen if you know how to find the centre of the screen.

Author:  StarGateSG-1 [ Fri Oct 07, 2005 12:41 pm ]
Post subject: 

Umm.. I am conused by your question, do you mean center the cursor in the middle of the screen... try locate(row,column)???????????

Author:  bass_maniac [ Fri Oct 07, 2005 2:19 pm ]
Post subject:  Re: How To Center An Input

Da_Big_Ticket wrote:
How can I make it so that turing will center the characters as they are inputted?


create a var called 'word' (or whatever). make another called 'input' that will be excepted by getch. make a loop. within that loop getch input. make word equal to word + input. locate the center of the screen minus half the length of word and put word. there will be issues with this code that you'll have to figure out, but i don't want to give the problem away. Part of the learning experience is figuring it out yourself. You'll remember it better if you do.

Author:  Da_Big_Ticket [ Fri Oct 07, 2005 9:04 pm ]
Post subject: 

Well ill try to clarify my problem:

Im not new to turing or anything, I know how to change the cursor location and how to do inputs and outputs etc. But the problem is that when the user is inputting the word they want to find the middle letter of, there is no saying how long the word is going to be in length because that is determined by the user of the program. I would like turing to center their input as it is being added to turing. I dont know if this is possible but it would make my program really good, and i would appreciate it greatly.

Thanks, DBT

Author:  Cervantes [ Sat Oct 08, 2005 8:13 am ]
Post subject: 

You might want to read through the String Manipulation tutorial. It will teach you about the length function, as well as many other things.
Also, you might need to know the mod function to determine if the word has an odd or even amount of letters.

This is entirely possible. Go for it!

Author:  bass_maniac [ Sat Oct 08, 2005 2:31 pm ]
Post subject: 

Da_Big_Ticket wrote:
But the problem is that when the user is inputting the word they want to find the middle letter of, there is no saying how long the word is going to be in length because that is determined by the user of the program. I would like turing to center their input as it is being added to turing.


In my last post I explained that. You are putting all the code in a loop and after each getch it adds the getched stuff to 'word', clears the screen and puts the value of 'word' and loops over and over, each time adding to 'word', clearing the screen, and putting the 'word' so it looks as though you're using a typewriter. Please try it out. It'll work.


: