Author |
Message |
Saad
|
|
|
|
|
Sponsor Sponsor
|
|
|
Lekegolo killer
|
Posted: Tue Dec 09, 2008 3:56 pm Post subject: Re: String Manipulation |
|
|
i took a bit of the code i found here and mophed it a bit so it looks like this:
var day2 :int
var day3 : string
loop
cls
locate (1, 1)
put "Requesting day of curent month"
get day3
if strintok (day3) then
day2 := strint (day3)
exit
else
put "That is not a valid number"
delay (1000)
end if
end loop
delay(1000)
cls
how would i make it so that it will only accept numbers under 31 as a valid number? (i am trying to get the day of the month without it crashing if they put in a invalid number). |
|
|
|
|
|
gitoxa
|
Posted: Tue Dec 09, 2008 4:24 pm Post subject: RE:String Manipulation |
|
|
You have to test the number to make sure it is smaller than 31 before assigning it to your variable. (after works too, but you dont want to assign bad data)
You'll want to check to make sure your number is 31 or less ( < 32 ) using the strint function before assigning it to your variable |
|
|
|
|
|
Lekegolo killer
|
Posted: Wed Dec 10, 2008 1:26 pm Post subject: Re: String Manipulation |
|
|
ohhhh kk i got it...i think... i put a if in a if. |
|
|
|
|
|
Flipmc
|
Posted: Fri Jan 30, 2009 6:37 pm Post subject: RE:String Manipulation |
|
|
Thanks a lot for this! |
|
|
|
|
|
Draconis
|
Posted: Tue May 05, 2009 9:30 pm Post subject: RE:String Manipulation |
|
|
Thanks sooo much man, i've been looking for something that gave out this info since foreverrrr! THANKS! =) |
|
|
|
|
|
stas054
|
Posted: Sat Jun 13, 2009 3:18 pm Post subject: RE:String Manipulation |
|
|
I <3 pie |
|
|
|
|
|
DaBigOne
|
Posted: Sun Dec 30, 2012 5:17 pm Post subject: Re: String Manipulation |
|
|
I am making a calculator, and this is what I got so far.
var num1 : real
var num2 : real
var reply : string
loop
put " what kind of function would you like to perform? type in '+', '-', '*', or '/'"
get reply
if reply = "/" or reply = "-" or reply = "*" or reply = "+" then
if reply = "+" then
put " What is the first number?"
get num1
put " What is the second number?"
get num2
put num1 + num2
end if
if reply = "-" then
put " What is the first number?"
get num1
put " What is the second number?"
get num2
put num1 - num2
end if
if reply = "*" then
put " What is the first number?"
get num1
put " What is the second number? "
get num2
put num1 * num2
end if
if reply = "/" then
put " What is the first number?"
get num1
put " What is the second number?"
get num2
put num1 / num2
end if
else
put " Invalid Function "
delay (1000)
end if
end loop
I managed to fix the problem at the beginning if someone types in something other than what the required symbols, as it makes a message pop up saying "Invalid Function"
However, after they put in the math symbol, the program asks them for a number.
I want to make sure they input a number (including real and integers) and nothing else, but I cannot seem to find out how to do that.
This tutorial only works for integers, but I want the user to be able to input real numbers as well; it is a calculator after all.
Any advice???? |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Insectoid
|
Posted: Sun Dec 30, 2012 6:04 pm Post subject: RE:String Manipulation |
|
|
strreal() and strrealok() |
|
|
|
|
|
DaBigOne
|
Posted: Mon Dec 31, 2012 4:16 pm Post subject: RE:String Manipulation |
|
|
so basically, strreal makes it so only numbers can be entered i take it, and strrealok does what? |
|
|
|
|
|
Insectoid
|
Posted: Mon Dec 31, 2012 4:24 pm Post subject: RE:String Manipulation |
|
|
Did you read the first post in this thread? If you still don't get it after that, you can check the Turing Documentation, which can be found by clicking the 'Turing' button at the top of the page. |
|
|
|
|
|
DaBigOne
|
Posted: Mon Dec 31, 2012 6:08 pm Post subject: RE:String Manipulation |
|
|
OK, yes I found that part. That helped a lot, thanks! |
|
|
|
|
|
|