Page 1 of 1
If commands
Posted: Tue Nov 23, 2004 10:09 pm
by typon
THanks for helping for the last one...i figured my way through
so now im actually gunna continue getting help
.
ok you have to use if commands and only + / - * . and NO turing built in functions to tell the user if the number entered by the user is a real number or integer.
i know it sounds easy but i have NO idea how i can do this.
plz help ill be reaaaallly grateful.
EDIT: oh yes and i use the windows version OOT
Archived topic from Iceteks, old topic ID:2864, old post ID:23403
If commands
Posted: Tue Nov 23, 2004 10:24 pm
by wtd
Well, Turing enforces types, so a variable has to be declared as int or real.
As a result, you'll always know.
Archived topic from Iceteks, old topic ID:2864, old post ID:23404
If commands
Posted: Tue Nov 23, 2004 11:32 pm
by Death
Yes, turing has to have the type enforced. You can't just sneak away without telling the computer what TYPE of variable it is. The only way the computer can tell without you specifying the type is to assign it a value. For example, if you say VAR X := "hello" turing will automatically associate it as a string. However, it is a good practice to assign the TYPE to your variables. That way, you'll know what they are in the future. Oh, while I'm on this subject, might as well tell you about commenting. Commenting isn't really executable coding in a program (which means that it does not affect how the program is run), but it is extremely important. Here's an example of commenting
%This is a comment
The coding for comments requires a single % symbol, then anything after it. What does commenting do? Well, it simply puts lines of text in the program. It doesn't do anything special to your program or anything. HOWEVER, it can prove to be most useful. You use commenting to talk about parts of your program. For example, you come to a part of your program, and while programming, you comment to tell others what your program will do. I use commenting alot for variables. I comment my variables and explain what each variable will do and why it is used. When your programs start to get really big (EX: 4000 lines), you'll NEED commenting to know where things are going to go. Commenting is also useful for setting link points in your program. If you need to find something, give the comment a unique name such as %MAIN PROGRAM and just go into the turing menu, select FIND WORD and type that in. The result is the program will jump to that line of text and bring you where you go (Very useful, saves time in trying to find an area of code). Here's an example of commenting variables:
%VARIABLE X: This variable is used in calculating the length of an object. It is given %the default value of 0 and is used in the area formula
VAR X: INT:= 0
This just explains what X will do. You see, before you even see variable X being used, you have a rough idea of what it will do. The next one is using a comment as a link point:
LOOP
PUT "HELLO"
END LOOP
If h = true then
end if
%CALCULATIONS
LOOP
%coding
%coding
END LOOP
%MAIN
FOR I: 1..3
%Lines of code
END FOR
You see, I have 2 linking comments. One being called CALCULATIONS and one called MAIN. So, no matter where I am in the coding of my program, all I have to do is select the FIND WORD section and type in MAIN, then the program will jump to that area and bring me where I need to go. So that's basically commenting. Commenting is simple, yet affective, especially if you are working in a group project or you decide to take a break from programming something for a very long time. That way, when you or somebody forgets what the variable or the program does, you can easily find out.
Archived topic from Iceteks, old topic ID:2864, old post ID:23408
If commands
Posted: Wed Nov 24, 2004 7:12 pm
by typon
sorry but that doesnt answer my question
i am asking that i have to make a program where user puts a number THEN the computer will tell the user whether they put a real number or an integer. and the outlines i already stated in my last post..
someone plzz help me
Archived topic from Iceteks, old topic ID:2864, old post ID:23410
If commands
Posted: Thu Nov 25, 2004 1:36 am
by wtd
Well, in Turing, the program to get the number would look something like:
Code: Select all
var number : int
get number[code]
Or maybe:
[code]var number : real
get number[code]
In either case, you've already stated whether the variable is an integer or floating point number.
What I suspect you mean, though, is, given that you declare the variable as a real, you want to know if someone just typed an integer anyway.
This is easy to find out. The basic process is to get just the integer part of the number, and compare it to the original. If they're the same, then clearly there was nothing after the decimal point.
The floor function will take a floating point number, and give you just the integer part.
[code]var number : real
get number
if number = floor (number) then
put "int"
else
put "real"
end if[code]
[color=#888888][size=85]Archived topic from Iceteks, old topic ID:2864, old post ID:23414[/size][/color]
If commands
Posted: Thu Nov 25, 2004 11:33 am
by typon
typon wrote: ok you have to use if commands and only + / - * . and NO turing built in functions
sorry man but you're getting really close and u understand wat i mean
but as i stated in my last post. you can not use any built in functions.
just implement what floor does by using boolean operators.
plz help meeee THANKS JRT><
Archived topic from Iceteks, old topic ID:2864, old post ID:23417
If commands
Posted: Fri Nov 26, 2004 10:44 pm
by Death
I know how to do that. You need to use a function called MODULUS. It's a built in function, called in an if statement. The coding is MOD. I hardly ever use MOD because I don't find it particularly useful. Although I don't remember the EXACT syntax, I'll be able to explain what it does. I believe that MOD takes a number and checks to see if it has remainders or not. If it does not have a remainder, MOD returns the value of 0 and if it DOES have a remainder, it returns the value of 1. You'll have to research about MOD in your turing manual (you do have one, riiiight?). But All I think you have to do is take the number, and MOD it to check if it has remainders or not. Obviously, if it has a remainder, it is a real number. Otherwise, if it has no remainders, it is an INT (Well, it's a real too, but that's beyond the point.). Anyways, if anyone else can remember what MOD does and how to use it, feel free to elaborate. I on the other hand, am out of brain juice and I don't have turing anymore to test my theories. EN JOY!
Archived topic from Iceteks, old topic ID:2864, old post ID:23426
If commands
Posted: Sat Nov 27, 2004 1:36 am
by wtd
That should work. Most languages only let modulus work on integers (as it should be), but Turing let's it work on decimal numbers as well.
Code: Select all
10.42 mod 1[code]
Yields:
[code].42[code]
[color=#888888][size=85]Archived topic from Iceteks, old topic ID:2864, old post ID:23427[/size][/color]
If commands
Posted: Sat Nov 27, 2004 12:33 pm
by typon
exactly wat i have been trying to do
subract 1 from the var entered by the user until it reaches 0
or if its a real number i t will reach 0.xxxxxx
but my teacher said i cant use mod i have to use operators
i have been looking for a way to subtract 1 from the number x amount of times (x is the first number to the left of the decimal.
THIS IS GETTING ON MY NEERVEEESSS
Archived topic from Iceteks, old topic ID:2864, old post ID:23431
If commands
Posted: Sat Nov 27, 2004 12:48 pm
by Red Squirrel
It gets worse, we're doing visual basic and we're not allowed to use conditional statements.
Archived topic from Iceteks, old topic ID:2864, old post ID:23432
If commands
Posted: Sat Nov 27, 2004 12:51 pm
by typon
Furball wrote: I on the other hand, am out of brain juice and I don't have turing anymore to test my theories. EN JOY!
do u want turing?
cuz i really love u guys and ur help
PS. HELP MEE ARGOIA#T*)Y#A*)%TH#Q)*%H)Q@*#%Q@#Y%G
Archived topic from Iceteks, old topic ID:2864, old post ID:23433
If commands
Posted: Sat Nov 27, 2004 7:21 pm
by Death
Sure, why not? I should really start up my programming again (Now that I have time
). Ya, I haven't learned all the new turing commands like the GUI stuff, but I probably would like to figure them out. A programmer can only explain so much without actually testing things out. Sure if I have turing, I'll DEFINATELY be able to figure out that previous question (I have a hunch, but needs testing)
.
Archived topic from Iceteks, old topic ID:2864, old post ID:23438
If commands
Posted: Sat Nov 27, 2004 9:37 pm
by wtd
typon wrote: exactly wat i have been trying to do
subract 1 from the var entered by the user until it reaches 0
or if its a real number i t will reach 0.xxxxxx
but my teacher said i cant use mod i have to use operators
i have been looking for a way to subtract 1 from the number x amount of times (x is the first number to the left of the decimal.
THIS IS GETTING ON MY NEERVEEESSS
Ok, your teacher is a frickin' moron. "mod" is an operator. It's an integral part of the language.
And subtracting one from a number like you want looks like:
Code: Select all
var number : real
get number
loop
exit when number < 1
number := number - 1
end loop[code]
If your teacher says you can't use loops, hit him or her for me, ok? :)
[color=#888888][size=85]Archived topic from Iceteks, old topic ID:2864, old post ID:23448[/size][/color]
If commands
Posted: Sun Nov 28, 2004 11:55 am
by typon
haha thanks man
I REALLY F***king HATE HER THoUGH
ill try thanks man <3
P.S Furball pm me ur email ill send turing its only like 3 mb or smth.
Archived topic from Iceteks, old topic ID:2864, old post ID:23453
If commands
Posted: Mon Nov 29, 2004 11:37 pm
by Death
LOL. Ya, your teacher must be a moron. I don't think SHE even knows how to do it. Still, it can't be as bad as MY programming teacher. Pretty sad when the student knows more than the teacher. Anyways, my email is
muitto101@hotmail.com.. Send it whenever and I'll be able to check out that MOD operand. Although I think that question was answered.
Archived topic from Iceteks, old topic ID:2864, old post ID:23472
If commands
Posted: Tue Nov 30, 2004 10:37 am
by typon
yeah wtd thats wat ur supposed to do.. use a loop
but how do i put the loop in an if command?
Archived topic from Iceteks, old topic ID:2864, old post ID:23478
If commands
Posted: Tue Nov 30, 2004 2:36 pm
by wtd
Ermmm... it's pretty simple.
Code: Select all
if ...
loop
...
end loop
end if[code]
[color=#888888][size=85]Archived topic from Iceteks, old topic ID:2864, old post ID:23484[/size][/color]