Computer Science Canada help - calender |
| Author: | whoareyou [ 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)
Please specify what version of Turing you are using 4.1.1 |
|||
| Author: | DemonWasp [ 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. |
|
| Author: | whoareyou [ 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. |
|
| Author: | Tony [ Fri Mar 04, 2011 3:45 pm ] | ||
| Post subject: | RE:help - calender | ||
what does
evaluate to? |
|||
| Author: | whoareyou [ Fri Mar 04, 2011 4:00 pm ] | ||
| Post subject: | Re: RE:help - calender | ||
Tony @ Fri Mar 04, 2011 3:45 pm wrote: what does
evaluate to? its a string, so if the user inputs Tuesday, then it should store than in "day" |
|||
| Author: | Tony [ Fri Mar 04, 2011 4:03 pm ] | ||
| Post subject: | RE:help - calender | ||
I meant as appears in your code
|
|||
| Author: | whoareyou [ 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. |
|
| Author: | Insectoid [ 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.
|
|||
| Author: | Tony [ Fri Mar 04, 2011 4:17 pm ] | ||
| Post subject: | RE:help - calender | ||
what's strange is that boolean operators were used correctly above
|
|||
| Author: | whoareyou [ 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. |
|
| Author: | DemonWasp [ 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". |
|
| Author: | whoareyou [ 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!
Very long just for the beginning! |
|||
| Author: | whoareyou [ 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 ? |
|
| Author: | Tony [ 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. |
|
| Author: | whoareyou [ Fri Mar 04, 2011 6:38 pm ] | ||
| Post subject: | Re: help - calender | ||
My code so far:
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. |
|||
| Author: | ihsh [ Fri Mar 04, 2011 8:00 pm ] | ||
| Post subject: | Re: help - calender | ||
You mean that when the dates have different amount of digits, they will mess up the overall alignment? Since the numbers only go from 1-31, you can use a simple if-structure to determine how many digits the number has and adjust the spacing according the length of the number . A code example (this is right aligned):
Also, keep in mind that the widths of the columns of your calender are inconsistent. For example, the "THURS" clolumn has two more characters than the "MON" column. This will make it harder to align as you'll need more if structures. You might consider changing the numerical values of this line to make sure that the widths of the columns are the same : Quote: put d1, " " : 10, d2, " " : 10, d3, " " : 10, d4, " " : 10, d5, " " : 10, d6, " " : 10, d7, " " : 10 |
|||
| Author: | whoareyou [ Fri Mar 04, 2011 9:23 pm ] |
| Post subject: | RE:help - calender |
it still isnt skipping to the next line. it just goes straight across. |
|
| Author: | Tony [ Fri Mar 04, 2011 9:30 pm ] |
| Post subject: | RE:help - calender |
You can use multiple put statements. Use .. at the end to keep everything on the same line. put an empty string "" to go to the next line. |
|
| Author: | whoareyou [ Fri Mar 04, 2011 10:04 pm ] | ||
| Post subject: | Re: help - calender | ||
i dont seem to be doing something right. maybe im not interpretting your suggestions right ...? here is my code, so you can take a look.
also, i've included a sample program of how the program should output. im testing mine with the days set to 30 and the starting date is monday. see how it goes from 1-6 in the first row, and then starts from 7 AT sunday in the second row? i don't understand why my program isn't doing that. |
|||
| Author: | ihsh [ Fri Mar 04, 2011 10:30 pm ] |
| Post subject: | RE:help - calender |
That doesn't align because the amount of spacing for the Sunday column is different. On all the other days, the spacing should be 10-15, whereas on Sundays the spacing is 3. Therefore if you want to use the spacing command, you will need to use an if-structure to check if it's a Sunday. If so, you'll have to use a different amount of spacing. In your case, you will just need to check if daycount=1 |
|
| Author: | whoareyou [ Sat Mar 05, 2011 2:34 pm ] | ||
| Post subject: | Re: help - calender | ||
now, i've got the sunday column all lined up, but when the numbers enter double digits, they get out of order. also, the first row of numbers dont line up with the rest i have to fix the column heads too; they aren't lined up with the rest of the numbers.
|
|||