horoscope has 5 different segments namely
WOOD, FIRE, EARTH, GOLD and WATER. The corresponding animals for these five
are DOG, CAT, RAT, TIGER and MONKEY. The date-line for each Horoscope is as
below:
WOOD December 20 to February 19
FIRE February 20 to April 19
EARTH April 20 to July 19
GOLD July 20 to October 19
WATER October 20 to Dec 19
In this program a user entered his date of birth in (12/03/1984) format. You need to
determine the zodiac sign of the user..
have an array of strings for segments (and one for animals if needed).
also have an array with turning dates. you could convert month and day to just days, but that would be a bit complicated. I suggest that you have two arrays - one with months and one with days. though since the days are all = 20, you don't need that second array.
the month array would be {2, 4, 7, 10, 12}.
now you have to find in which gap the entered month is.
for example if user entered 11, 11 is between 10 and 12, so your function should return 4. (meaning 4'th segement = "GOLD")
if user entered 12 we can't tell if it's 4 or 5. have the first step return 4. Then compare day with 20. if it's before 20, it's 4. otherwise it's 5.
you'll have lots of work if you want to read the whole thing into a string and then extract numbers form it.
consider code int i; cin >> i;. If you enter "5", it will read 5. what if you enter "5/2"? it will read the 5 and since "/" is not a part of a number, and i is an integer, cin will leave the "/2" in the stream for the next operation. you can then skip one char with cin.ignore() and read another number
so for date 2/11/2011 you have to cin >> month; cin.ignore(); cin >> day; cin.ignore(); cin >> year;