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

Username:   Password: 
 RegisterRegister   
 help - calender
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
whoareyou




PostPosted: Fri Mar 04, 2011 9:53 am   Post subject: help - calender

What is it you are trying to achieve?
To create a user-generated calender using repetition commands.

Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)

Turing:


var nodays:int
var day:string

loop
put "How many days are there?"
get nodays

if nodays > 31 then
put "Please try again!"
end if
exit when nodays = 31 or nodays = 30 or nodays = 29 or nodays = 28

end loop

loop
put "What day does the month start on?"
get day

if day not = "Monday" or "Tuesday" or "Wednesday" or "Thursday" or "Friday" then




Please specify what version of Turing you are using
4.1.1
Sponsor
Sponsor
Sponsor
sponsor
DemonWasp




PostPosted: Fri Mar 04, 2011 10:29 am   Post subject: RE:help - calender

You forgot the part where you're supposed to tell us what problem you're having. Without that, we have no idea what you want help with.
whoareyou




PostPosted: Fri Mar 04, 2011 3:26 pm   Post subject: RE:help - calender

i tried testing that code that i have there before i move on, but it says operands of bollean operators must be boolean and "Tuesday" is highlighted.
Tony




PostPosted: Fri Mar 04, 2011 3:45 pm   Post subject: RE:help - calender

what does
code:

"Tuesday" or "Wednesday"

evaluate to?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
whoareyou




PostPosted: Fri Mar 04, 2011 4:00 pm   Post subject: Re: RE:help - calender

Tony @ Fri Mar 04, 2011 3:45 pm wrote:
what does
code:

"Tuesday" or "Wednesday"

evaluate to?


its a string, so if the user inputs Tuesday, then it should store than in "day"
Tony




PostPosted: Fri Mar 04, 2011 4:03 pm   Post subject: RE:help - calender

I meant as appears in your code
code:

if "Tuesday" or "Wednesday" then
   put "what is this?"
end if
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
whoareyou




PostPosted: Fri Mar 04, 2011 4:06 pm   Post subject: RE:help - calender

if the user enters monday, or tuesday, or wednesday ... etc, then it should store it in the variable day.

if not, i have to add in that it is invalid, and it should repeat that part until the user enters one of the 7 possible values for days.
Insectoid




PostPosted: Fri Mar 04, 2011 4:13 pm   Post subject: RE:help - calender

That's not the way conditionals work. You need to compare each individual day to the input.

code:

if day != "monday" and day != "tuesday" and...
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Fri Mar 04, 2011 4:17 pm   Post subject: RE:help - calender

what's strange is that boolean operators were used correctly above
code:

exit when nodays = 31 or nodays = 30 or nodays = 29 or nodays = 28
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
whoareyou




PostPosted: Fri Mar 04, 2011 4:19 pm   Post subject: RE:help - calender

maybe its because i used a string. i think i need to change it to an integer, and associate each day with a number.
DemonWasp




PostPosted: Fri Mar 04, 2011 4:21 pm   Post subject: RE:help - calender

What Tony is hinting at is that that condition isn't doing what you think it is. The error message is actually pretty direct here. It's telling you that the operator "or" only works on booleans. That means that the value to the left and the value to the right must BOTH be booleans.

When Turing looks at your code file, it sees it like this:

if - starting an if-statement, good
day not= "Monday" - conditional, returns boolean, good
or "Tuesday" - what's that supposed to mean?!

What you really mean is this:
if not ( day = "Monday" or day = "Tuesday" or ... ) then

This gives you the logic you are after. First, you compare the value in day against each of "Monday"..."Friday"; if it matches any of those values, then the contents of the parenthesis returns true. You then negate that result with "not" and end up with true if and only if the value in day is NOT one of "Monday"..."Tuesday".
whoareyou




PostPosted: Fri Mar 04, 2011 5:26 pm   Post subject: Re: RE:help - calender

DemonWasp @ Fri Mar 04, 2011 4:21 pm wrote:
What Tony is hinting at is that that condition isn't doing what you think it is. The error message is actually pretty direct here. It's telling you that the operator "or" only works on booleans. That means that the value to the left and the value to the right must BOTH be booleans.

When Turing looks at your code file, it sees it like this:

if - starting an if-statement, good
day not= "Monday" - conditional, returns boolean, good
or "Tuesday" - what's that supposed to mean?!

What you really mean is this:
if not ( day = "Monday" or day = "Tuesday" or ... ) then

This gives you the logic you are after. First, you compare the value in day against each of "Monday"..."Friday"; if it matches any of those values, then the contents of the parenthesis returns true. You then negate that result with "not" and end up with true if and only if the value in day is NOT one of "Monday"..."Tuesday".


THAT WAS CORRECT! :O
Thank you!

So by using your technique, my code now works and looks like this. However, it is not finished. If i run into more problems, i'll be sure to post back here!

Turing:


var numberof:int
var day:string

loop
put "How many days are there?"
get numberof

if numberof > 31 or numberof < 28 then
put "Please try again!"
end if
exit when numberof = 31 or numberof = 30 or numberof = 29 or numberof = 28

end loop

loop
put "What day does the month start on?"
get day

if day = "Monday" or day = "Tuesday" or day = "Wednesday" or day = "Thursday" or day = "Friday" then
else
put "That is not a valid day!"

end if
exit when day = "Monday" or day = "Tuesday" or day = "Wednesday" or day = "Thursday" or day = "Friday"
end loop



Very long just for the beginning!
whoareyou




PostPosted: Fri Mar 04, 2011 6:08 pm   Post subject: RE:help - calender

how should align the numbers so that they appear under each appropriate day ?
Tony




PostPosted: Fri Mar 04, 2011 6:23 pm   Post subject: RE:help - calender

Using spaces. Documentation for put might have a shortcut for that, but it's the same idea.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
whoareyou




PostPosted: Fri Mar 04, 2011 6:38 pm   Post subject: Re: help - calender

My code so far:

Turing:


setscreen ("text")

var nodays:int
var day:string
var daycount:int:=0
loop
put "How many days are there?"
get nodays

if nodays > 31 or nodays < 28 then
put "Please try again!"
end if
exit when nodays = 31 or nodays = 30 or nodays = 29 or nodays = 28

end loop

loop
put "What day does the month start on?"
get day

if day = "Monday" or day = "Tuesday" or day = "Wednesday" or day = "Thursday" or day = "Friday"
 or day = "monday" or day = "tuesday" or day = "wednesday" or day = "thursday" or day = "friday"
then
else
put "That is not a valid day!"

end if
exit when day = "Monday" or day = "Tuesday" or day = "Wednesday" or day = "Thursday" or day = "Friday"
or day = "monday" or day = "tuesday" or day = "wednesday" or day = "thursday" or day = "friday"
end loop


put skip
var d1, d2, d3, d4, d5, d6, d7 : string
d1 := "SUN"
d2 := "MON"
d3 := "TUES"
d4 := "WED"
d5 := "THURS"
d6 := "FRI"
d7 := "SAT"

put d1, " ":10, d2, " ":10, d3, " ":10, d4, " ":10, d5, " ":10, d6, " ":10, d7, " ":10

if day = "Monday" or day = "monday" then
for i: 1 .. nodays
put " ", i:10..
daycount += 1



if (daycount mod 7 = 0) then
put ""
daycount := 0
end if

end for
end if



I have it set up so that it will run when i enter 30 days and the start date is on monday.
however, the numbers won't allign under the right date properly.

i dont underestand how i can use spaces, because then each number will get spaces and it will go off the calender.
also, it won't go onto the next line once it reaches saturday.
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 2  [ 21 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: