Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 String Manipulation
Index -> Programming, Turing -> Turing Tutorials
Goto page Previous  1, 2
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Saad




PostPosted: Sun Oct 12, 2008 9:24 am   Post subject: RE:String Manipulation

Added to Wiki
Turing String Manipulation
Sponsor
Sponsor
Sponsor
sponsor
Lekegolo killer




PostPosted: 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




PostPosted: 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




PostPosted: 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




PostPosted: Fri Jan 30, 2009 6:37 pm   Post subject: RE:String Manipulation

Thanks a lot for this!
Draconis




PostPosted: 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




PostPosted: Sat Jun 13, 2009 3:18 pm   Post subject: RE:String Manipulation

I <3 pie
DaBigOne




PostPosted: 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
Sponsor
sponsor
Insectoid




PostPosted: Sun Dec 30, 2012 6:04 pm   Post subject: RE:String Manipulation

strreal() and strrealok()
DaBigOne




PostPosted: 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




PostPosted: 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




PostPosted: Mon Dec 31, 2012 6:08 pm   Post subject: RE:String Manipulation

OK, yes I found that part. That helped a lot, thanks!
Display posts from previous:   
   Index -> Programming, Turing -> Turing Tutorials
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 2 of 2  [ 27 Posts ]
Goto page Previous  1, 2
Jump to:   


Style:  
Search: