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

Username:   Password: 
 RegisterRegister   
 Getting the current data in turing
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
alt+f4




PostPosted: Sat Mar 17, 2007 1:01 pm   Post subject: Getting the current data in turing

Hello i am trying to write a program that sloves this question:

9. Write a program that asks the user their name and date of birth, the program will output their age and appropriate comment whether they can have their G1, G2 and/or vote.

I am having trouble getting the current date so that i can calculate the users age so far i have this... I am using the Time.date function and turing 4.0.3 I belive that the problem is that Time.date is a string. Is there a better way to get the current day, month and year in turing. And i am sorry this is probley a really easy question. i am not really this bad at coding i just dont know the syntax in turing yet.
code:

%Age displaying

%Variables
var name, currentdate : string
var day, month, year, age: int

%Input
put "Please Enter your name"
get name : *
put "Please Enter your date of birth(DD MM YYYY)with spaces"
get day
get month
get year

%if/else
if day > 0 and day < 32 then
else
    put "Invalid day"
end if

if month > 0 and month < 13 then
else
    put "Invalid month"
end if

%Calculate
currentdate := Time.Date
put currentdate
[/code]
Sponsor
Sponsor
Sponsor
sponsor
CodeMonkey2000




PostPosted: Sat Mar 17, 2007 4:06 pm   Post subject: RE:Getting the current data in turing

You may want to read up on string manipulation. Some useful functions you might need are strint() and length().
alt+f4




PostPosted: Mon Mar 19, 2007 8:20 am   Post subject: Re: Getting the current data in turing

:UPDATE

I got my program running with a static date it looks like this now...

code:

%Age displaying

%Variables
var name : string
var day, cday, month, cmonth, year, cyear, age : int

%Set current day
cday := 19
cmonth := 03
cyear := 2007

%Statements
age := 0

%Input
put "Please Enter your name"
get name : *
put "Please Enter your date of birth(DD MM YYYY)with spaces"
get day
get month
get year

%if/else
if day > 0 and day < 32 then
else
    put "Invalid day"
end if

if month > 0 and month < 13 then
else
    put "Invalid month"
end if
if month > cmonth then
    age := age - 1
elsif day > cday and age not= -1 then
    age := age - 1
else
    put "Error please try agian later"
end if

%Calculate
age := (cyear + age) - year

%if/else
if age < 0 then
    put name," You are ", age, " and you are not yet born"
elsif age > 15 and age < 16 then
    put name," You are ", age, " and you can get your G1"
elsif age > 16 and age < 18 then
    put name," You are ", age, " and you can get your G1 then G2"
elsif age > 18 then
    put name," You are ", age, " and you can get your G1, and G2 and vote"
else
    put name," You are ", age, " and you are not old enough yet to drive or vote"
end if
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: