An interesting piece of code.

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.