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 Previous  1, 2
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
ihsh




PostPosted: 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):
Turing:

for i : 1 .. nodays
        if i < 10 then
            put " " : 12, i ..
        else
            put " " : 11, i ..
        end if

        %rest of for loop....
        %...
end for


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
Sponsor
Sponsor
Sponsor
sponsor
whoareyou




PostPosted: 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.
Tony




PostPosted: 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.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
whoareyou




PostPosted: 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.

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:12, d3:14, d4:14, d5:14, d6:14, d7:12

if day = "Monday" or day = "monday" then
for i: 1 .. 6
put i:11..
end for
put skip

for i: 7 .. nodays

put i:10..
daycount += 1
if (daycount = 7) then
put skip
daycount := 0



end if
end for
end if



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.



Repetition3.rar
 Description:
test with number of days at 30 and starting from monday.

Download
 Filename:  Repetition3.rar
 Filesize:  226.51 KB
 Downloaded:  146 Time(s)


Repetition3.rar
 Description:
test with number of days at 30 and starting from monday.

Download
 Filename:  Repetition3.rar
 Filesize:  226.51 KB
 Downloaded:  133 Time(s)

ihsh




PostPosted: 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
whoareyou




PostPosted: 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 Sad
i have to fix the column heads too; they aren't lined up with the rest of the numbers.

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:12, d3:14, d4:14, d5:14, d6:14, d7:12

if day = "Monday" or day = "monday" then
for i: 1 .. 6
put " ", i:10..
end for
put skip

for i: 7 .. nodays
daycount += 1

if (daycount = 1) then
put i..
end if

if (daycount mod 7 = 0) then
put i:10..
put skip
daycount := 0
end if

if (daycount > 1) and (daycount < 7) then
put i:10..
end if




end for
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 2 of 2  [ 21 Posts ]
Goto page Previous  1, 2
Jump to:   


Style:  
Search: