Computer Science Canada Help needed for a turing program |
Author: | Tad905 [ Sat Mar 17, 2012 12:15 pm ] |
Post subject: | Help needed for a turing program |
I have a question about a program I'm working on. I have put the part(s) that's causing a problem in running the program in a separate line. Thanks in advance. ------------------------------------------------------- Here's the program: ------------------------------------------------------- % This program will allow the user to enter their name, the year, month and day they were born and the current year, month and day in order to calculate the user's age. var name : string var year : int var month : int var day : int var currentYear : int var currentMonth : int var currentDay : int var age : int put "What is your full name?" get name : * % stores name entered by user cls % clears information entered put "Only type numbers for the following questions:" % tells user to enter digets only put "" % creates a single blank line (as if you pressed "Enter") put "1. What year were you born in? (i.e., 1985)" get year % stores year entered by user cls put "2. What month were you born in? (i.e. 1)" get month cls put "3. What day were you born on? (i.e. 1)" get day cls put "4. What is the Current Year?" get currentYear % stores current year entered cls put "5. What is the Current Month?" get currentMonth cls put "6. What is the Current Day?" get currentDay cls put "Congratulations ", name, "!" if month = 1 or 3 or 5 or 7 or 8 or 10 or 12 then put "You are ", currentYear-year-1, " years ", currentMonth-month+11, " month(s) and ", currentDay-day+31, " day(s) old" end if if month = 4 or 6 or 9 or 11 then put "You are ", currentYear-year-1, " years ", currentMonth-month+11, " month(s) and ", currentDay-day+30, " day(s) old" end if if month = 2 then put "You are ", currentYear-year-1, " years ", currentMonth-month+11, " month(s) and ", currentDay-day+28, " day(s) old" end if % calculates the users age based on previously entered information |
Author: | mirhagk [ Sat Mar 17, 2012 12:46 pm ] | ||
Post subject: | RE:Help needed for a turing program | ||
you need to do the following:
Turing (as well as most languages) don't assume your still checking month. |
Author: | Raknarg [ Sat Mar 17, 2012 3:31 pm ] |
Post subject: | RE:Help needed for a turing program |
yes. When you put or, you're indicating that the next clause is a seperate boolean operator. When you say month = 1 or 3, you're saying if the first statement is true or the next statement is true. 3 cannot be true, because it's not a boolean operator. |