Computer Science Canada turing - help w current year |
Author: | comp_help [ Sun Mar 29, 2009 6:13 pm ] |
Post subject: | 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? |
Author: | Dusk Eagle [ Sun Mar 29, 2009 7:54 pm ] | ||||
Post subject: | Re: turing - help w current year | ||||
Use Time.Date. If you want to store the year in a variable, simply type:
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:
I don't think you need to worry about your program being used in 2100 . |
Author: | comp_help [ Sun Mar 29, 2009 9:45 pm ] |
Post subject: | 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! Nvm, I think I got it! after experiemnting with the code. |
Author: | Dusk Eagle [ Sun Mar 29, 2009 10:20 pm ] | ||||||||||||||
Post subject: | Re: turing - help w current year | ||||||||||||||
Take a look at the following code:
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:
From this, we can see that the year is output at the eighth and ninth positions in the string. Even if it were, say April 2nd, the year would be the eighth and ninth characters of this string, as the day would be output as " 2" (note the space before 2). Knowing this, you might think the following would work:
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:
We then call it by doing the following:
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:
Instead, you must do the following:
|
Author: | comp_help [ Mon Mar 30, 2009 6:23 pm ] | ||||
Post subject: | Re: turing - help w current year | ||||
Dusk Eagle Thank you for that explaintion But I used another funtion than Time.Date:
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
|
Author: | Dusk Eagle [ Mon Mar 30, 2009 7:39 pm ] |
Post subject: | Re: turing - help w current year |
comp_help wrote: 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 And you can see how to format Turing Code from the mod edit of our own post.[/quote] |