From: http://www.oschina.net/code/snippet_10896_2907
[Code]
Gustmirthdate. cpp
/** <Br/> * an interesting piece of code to guess the birthday. <Br/> * run the program and make five choices to know the day of your birthday. Amazing! <Br/> */<br/> # include <iostream> <br/> using namespace STD; <br/> int main () <br/>{< br/> int date = 0; // Date to be determind <br/> char answer; <br/> // prompt the user for set 1 <br/> cout <"is your birth date in this set? "<Endl; <br/> cout <"16 17 18 19/N" <br/> "20 21 22 23/N" <br/> "24 25 26 27 /n "<br/>" 28 29 30 31 "<Endl; <br/> cout <"Enter N for no and Y for yes:"; <br/> CIN> answer; <br/> If (answer = 'y') <br/> date + = 16; <br/> // prompt the user for Set 2 <br/> cout <"is your birth date in this set? "<Endl; <br/> cout <"8 9 10 11/N" <br/> "12 13 14 15/N" <br/> "24 25 26 27 /n "<br/>" 28 29 30 31 "<Endl; <br/> cout <"Enter N for no and Y for yes:"; <br/> CIN> answer; <br/> If (answer = 'y') <br/> date + = 8; <br/> // prompt the user for Set 3 <br/> cout <"is your birth date in this set? "<Endl; <br/> cout <"1 3 5 7/N" <br/> "9 11 13 15/N" <br/> "17 19 21 23 /n "<br/>" 25 27 29 31 "<Endl; <br/> cout <"Enter N for no and Y for yes:"; <br/> CIN> answer; <br/> If (answer = 'y') <br/> date + = 1; <br/> // prompt the user for set 4 <br/> cout <"is your birth date in this set? "<Endl; <br/> cout <"2 3 6 7/N" <br/> "10 11 14 15/N" <br/> "18 19 22 23 /n "<br/>" 26 27 30 31 "<Endl; <br/> cout <"Enter N for no and Y for yes:"; <br/> CIN> answer; <br/> If (answer = 'y') <br/> date + = 2; <br/> // prompt the user for set 5 <br/> cout <"is your birth date in this set? "<Endl; <br/> cout <"4 5 6 7/N" <br/> "12 13 14 15/N" <br/> "20 21 22 23 /n "<br/>" 28 29 30 31 "<Endl; <br/> cout <"Enter N for no and Y for yes:"; <br/> CIN> answer; <br/> If (answer = 'y') <br/> date + = 4; <br/> cout <"your birth date is" <date <Endl; <br/> return 0; <br/>}
[Code]
Test my birthday
David @ xmimx: gustmirthdate $./gustmirthdate <br/> is your birth date in this set? <Br/> 16 17 18 19 <br/> 20 21 22 23 <br/> 24 25 26 27 <br/> 28 29 30 31 <br/> enter N for no and y for yes: n <br/> is your birth date in this set? <Br/> 8 9 10 11 <br/> 12 13 14 15 <br/> 24 25 26 27 <br/> 28 29 30 31 <br/> enter N for no and y for yes: Y <br/> is your birth date in this set? <Br/> 1 3 5 7 <br/> 9 11 13 15 <br/> 17 19 21 23 <br/> 25 27 29 31 <br/> enter N for no and y for yes: n <br/> is your birth date in this set? <Br/> 2 3 6 7 <br/> 10 11 14 15 <br/> 18 19 22 23 <br/> 26 27 30 31 <br/> enter N for no and y for yes: n <br/> is your birth date in this set? <Br/> 4 5 6 7 <br/> 12 13 14 15 <br/> 20 21 22 23 <br/> 28 29 30 31 <br/> enter N for no and y for yes: Y <br/> your birth date is 12