
-----------------------------------
comp_help
Sun Mar 29, 2009 6:13 pm

turing - help w current year
-----------------------------------
How to find the current year?

I outputted the year by the date funtion and asked for the input of the year according to that.

Is there any other way, that is without input?  :?

-----------------------------------
Dusk Eagle
Sun Mar 29, 2009 7:54 pm

Re: turing - help w current year
-----------------------------------
Use Time.Date. If you want to store the year in a variable, simply type:


var x := Time.Date () (8..9)


The first set of brackets after Time.Date simply tell the compiler that no parameters are being passed to the function.

The above code will store the year as "09". if you want to add the "20" to the start of it, just type:


var x := "20" + Time.Date () (8..9)


I don't think you need to worry about your program being used in 2100 :wink: .

-----------------------------------
comp_help
Sun Mar 29, 2009 9:45 pm

Re: turing - help w current year
-----------------------------------
Thank You Very Much Dusk Eagle! :) 

var x := Time.Date () (8..9) 

Can you please explain me the funtion of the brackets after Time.Date? 

Thank you again! 8-)

Nvm, I think I got it! :idea:  after experiemnting with the code.

-----------------------------------
Dusk Eagle
Sun Mar 29, 2009 10:20 pm

Re: turing - help w current year
-----------------------------------
Take a look at the following code:


put "hello world"(7..11)


This code outputs the text "world". The brackets tell it to only output the seventh to eleventh character of the string. Change the values around to experiment if you wish.

Now, if we look at the output from Time.Date, we see the following:


var year : string := Time.Date (8..9)


However, this raises a syntax error: "Call to 'Date' as too many parameters." What's this mean? Turing thinks you are trying to pass a parameter to the Time.Date function, while the Time.Date function does not accept any parameters. To understand this, let's take a look at a function that adds five to a number:


fcn add5 (num : int) :int %The parameter in this case is 'num'
    result num+5
end add5


We then call it by doing the following:


var x : int := add5 (6)

%x now has a value of 11


However, Time.Date does not accept any parameters (why would it need to?) Therefore, we must put an empty set of brackets after Time.Date to show that no parameters are being passed to it. After we do that, then we can specify which characters to output.

One other important thing to note: The variable 'year' must a string. Therefore, the following will not work:


var year : int := Time.Date() (8..9)


Instead, you must do the following:


var year_as_string : string := "20" +Time.Date() (8..9)
var year : int := strint(year_as_string)


-----------------------------------
comp_help
Mon Mar 30, 2009 6:23 pm

Re: turing - help w current year
-----------------------------------
Dusk Eagle Thank you for that explaintion :) 

But I used another funtion than Time.Date:

var today: string
date (today)
var day:= "20" + today (8..9)
var yr: int

yr:= strint (day)

I didn't have to use the blank brakets in this one. Is it because the today was declared as a variable? :? 

Also can you tell me how to put my turing code in a "Turing Code" box?


Mod Edit: Remember to use syntax tags! Thanks :) Code Here

-----------------------------------
Dusk Eagle
Mon Mar 30, 2009 7:39 pm

Re: turing - help w current year
-----------------------------------

I didn't have to use the blank brakets in this one. Is it because the today was declared as a variable?


Yes, if you declare either one as a variable, you won't have to put the extra set of brackets. I was just avoiding excess variables  :P 

And you can see how to format Turing Code from the mod edit of our own post.[/quote]
