Latest Diablo 3 News
Support the site! Become a Diablo: IncGamers PAL - Remove ads and more!

# Help Needed with a Turbo Pascal Program

Discussion in 'Off-Topic' started by Rune-Templar, Mar 22, 2004.

1. ### Rune-TemplarIncGamers Member

Joined:
Jul 31, 2003
Messages:
447
0
Trophy Points:
98
Help Needed with a Turbo Pascal Program

Hopefully whoever's reading this is already familiar with Turbo Pascal, because I won't really be explaining any terminology. For our next assignment, our teacher asked us to write an "Input Checker" program. The program is supposed to determine the variable type of the input (i.e. string, real, integer, character). So an input of "Diablo 2", would be a string; whereas an input of 4e2, would be a real. Any help is appreciated.

~Rune-Templar

2. ### P2blrIncGamers Member

Joined:
Jun 21, 2003
Messages:
784
0
Trophy Points:
165
Dude!

that sounds extremely simple, and I'm only in my second term of Comp. Sci (using TPW as well)

here's what I would do, search the length of the inputted string(ALWAYS use strings for input) if all characters are numbers, then it might be a shortint, byte, integer, or longint, or if there's one decimal point, then it's real, anything else and it's string

3. ### Rune-TemplarIncGamers Member

Joined:
Jul 31, 2003
Messages:
447
0
Trophy Points:
98
All right, but how do I check if it the input (string) has any numbers? BTW, my teacher announced that we can't use any functions in this program either >_< I was using the val function to check for numbers, but now I can't.

~Rune-Templar

4. ### P2blrIncGamers Member

Joined:
Jun 21, 2003
Messages:
784
0
Trophy Points:
165
what kind of teacher says you can't use functions?

I'd make almost every block of code a function, just to spite them

anyway, here's a simple way to tell if a character in a string is numeric:

Code:
For Counter := 1 to Length(InputString) do
if (Ord(InputStr[Counter])<48{'0'})or(Ord(InputStr[Counter])>57{'9'}) then
{There are non-numbers}
or, if your teacher really wants to be a ****, then you probably can't eve use Length or Ord (length of string and ordinance of character, respectively)

so I guess... here's a way to do it without those :S
Code:
Count := 0;
repeat
Count := Count + 1;
if (InputStr[Counter]>'9') ot (InputStr[Counter]<'0') then
{There are non-numbers}
until (InputStr[Counter]<' ') and (InputStr[Counter]>{whatever character 256 is});

hope that helps

EDIT:

if ya want, I could e-mail you a unit that has a few useful procedures and functions that I've made

5. ### Rune-TemplarIncGamers Member

Joined:
Jul 31, 2003
Messages:
447
0
Trophy Points:
98
Wow...you must be a programming genius or something, cuz most of what you wrote just went right over my head. You're really good at this programming stuff for a second term (I'm in second term as well), but I'll just ask my friends because they can explain it easier than you can over the Internet. Thanks though!

~Rune-Templar

6. ### JimmehIncGamers Member

Joined:
Sep 7, 2003
Messages:
818
0
Trophy Points:
255
i made battleships in turbo pascal :clap:

7. ### P2blrIncGamers Member

Joined:
Jun 21, 2003
Messages:
784
0
Trophy Points:
165
here's how it works:

look at first character in string program asks "are you a character between 0 and 9?" if the string says "no" then you know that you aren't working with a numerical type
then it goes to next character, and so on and so on until it's over, if all characters are numbers, then you're good :thumbsup:
if not, then it's a string or real, just need something to check if a number is real (just checking if there is only one "." in it) and there ya go

heh, right now we're doing "Complex Numbers": teacher puts in a file, has numbers in it in special format where one line is how many pairs of numbers, and the next line is the numbers and we have to do the four basic things to all of them (+-*/)
just need to check something and then am done

8. ### P2blrIncGamers Member

Joined:
Jun 21, 2003
Messages:
784
0
Trophy Points:
165
heh, actually, now I need some help
we are supposed to have a sorting algorithm made ourselves, but every time I try to sort some cards I just do one of the three main ones: Bubble, Insertion, or Selection sorts

it has to be better than or equal to O(n^2) and I just can't think of anything >_<