|
Post by kilborn on Apr 26, 2009 19:06:32 GMT
I am having a hell of a problem understanding the Mod function and using it to determine which chinese zodiac sign, given an input year. I have the psuedo-code as well as basic, so far? I just can't seem to get it to do anything.
so far this is what I have...
baseYear = integer birthYear = integer zodiacSign = string offset = integer
baseYear = 1900 Prompt for birthYear Get birthYear offset = (birthYear - baseYear) MOD 12
Select Case offset Case 0 : zodiacSign = "Rat" Case 1 : zodiacSign = "Ox" Case 2 : zodiacSign = "Tiger" Case 3 : zodiacSign = "Rabbit" Case 4 : zodiacSign = "Dragon" Case 5 : zodiacSign = "Snake" Case 6 : zodiacSign = "Horse" Case 7 : zodiacSign = "Sheep" Case 8 : zodiacSign = "Monkey" Case 9 : zodiacSign = "Rooster" Case 10 : zodiacSign = "Dog" Case 11 : zodiacSign = "Boar"
End Select Display birthYear, zodiacSign End
the idea is to get all that, to display the following message
CIS122 Lab2B: Chinese Zodiac Exercise Enter a year after 1899: (input year) (input year) is the year of the "zodiacSign" Thank You
can someone please help?
Kilborn
|
|
|
Post by kilborn on Apr 27, 2009 5:11:32 GMT
Update ** I think I mostly figured it out...but I can't get it to display the zodiacSign? here is the updated code?/ DIM baseYear AS INTEGER DIM birthYear AS LONG DIM zodiacSign AS STRING DIM offSet AS INTEGER
baseYear = 1900 offSet = (birthYear - baseYear) MOD 12
SELECT CASE offSet CASE 0: zodiacSign = "Rat" CASE 1: zodiacSign = "Ox" CASE 2: zodiacSign = "Tiger" CASE 3: zodiacSign = "Rabbit" CASE 4: zodiacSign = "Dragon" CASE 5: zodiacSign = "Snake" CASE 6: zodiacSign = "Horse" CASE 7: zodiacSign = "Sheep" CASE 8: zodiacSign = "Monkey" CASE 9: zodiacSign = "Rooster" CASE 10: zodiacSign = "Dog" CASE 11: zodiacSign = "Boar" END SELECT
CLS PRINT "CIS122 Lab2B: Chinese Zodiac Exercise" INPUT "Enter a year after 1899: ", birthYear PRINT birthYear; "is the year of the "; zodiacSign PRINT "Thank You" END
|
|
|
Post by Kilborndj on Apr 27, 2009 7:26:58 GMT
*Update*
'***************************************** '* CIS122SP09 Lab1 - Due 4/11/09 * '* Dave Johnson - This is solely my work * '*****************************************
DIM baseYear AS INTEGER DIM birthYear AS INTEGER DIM zodiacSign AS STRING DIM offset AS LONG
baseYear = 1900
CLS PRINT "CIS122 Lab2B: Chinese Zodiac Exercise" INPUT "Enter a year after 1899: ", birthYear offset = (birthYear / baseYear) MOD 12 SELECT CASE offset CASE 0: zodiacSign = "Rat" CASE 1: zodiacSign = "Ox" CASE 2: zodiacSign = "Tiger" CASE 3: zodiacSign = "Rabbit" CASE 4: zodiacSign = "Dragon" CASE 5: zodiacSign = "Snake" CASE 6: zodiacSign = "Horse" CASE 7: zodiacSign = "Sheep" CASE 8: zodiacSign = "Monkey" CASE 9: zodiacSign = "Rooster" CASE 10: zodiacSign = "Dog" CASE 11: zodiacSign = "Boar" END SELECT PRINT birthYear; "is the year of the "; zodiacSign PRINT "Thank You" END
** Now the mod function always displays Ox as the answer **
Can anyone help me out?
Dave "Kilborn" Johnson
|
|
|
Post by Mikrondel on Apr 28, 2009 0:04:10 GMT
This should fix it:
offset = (birthYear - baseYear) MOD 12
|
|