功能
用到的觀念
switch
CODE
#include"iostream"//標頭檔
#include"iomanip"
#include"cmath"
using namespace std;
using std::setw;
using std::fixed;
using std::setprecision;
int _tmain(int argc, _TCHAR* argv[])
{
int a,b,input;//declare variable
cout<<"The Twelve Days of Christmas";//顯示內容
cout<<"if you want to read the first day, press 1. if you want to read the
second day, press 2"<<endl;
cout<<"and type the following number to read what you want"<<endl;
cout<<"press -1 and it exit"<<endl;
do//do the program first
{cin>>input;//enter and save to input
if(input==1)
{
cout<<"On the first day of Christmas"<<endl;
cout<<"my true love sent to me:"<<endl;
}
else if(input==2)
{
cout<<"On the second day of Christmas"<<endl;
cout<<"my true love sent to me:"<<endl;
}
else if(input==3)
{
cout<<"On the third day of Christmas"<<endl;
cout<<"my true love sent to me:"<<endl;
}
else if(input==4)
{
cout<<"On the fourth day of Christmas"<<endl;
cout<<"my true love sent to me:"<<endl;
}
else if(input==5)
{
cout<<"On the fifth day of Christmas"<<endl;
cout<<"my true love sent to me:"<<endl;
}
else if(input==6)
{
cout<<"On the sixth day of Christmas"<<endl;
cout<<"my true love sent to me:"<<endl;
}
else if(input==7)
{
cout<<"On the seventh day of Christmas"<<endl;
cout<<"my true love sent to me:"<<endl;
}
else if(input==8)
{
cout<<"On the eighth day of Christmas"<<endl;
cout<<"my true love sent to me:"<<endl;
}
else if(input==9)
{
cout<<"On the ninth day of Christmas"<<endl;
cout<<"my true love sent to me:"<<endl;
}
else if(input==10)
{
cout<<"On the tenth day of Christmas"<<endl;
cout<<"my true love sent to me:"<<endl;
}
else if(input==11)
{
cout<<"On the eleventh day of Christmas"<<endl;
cout<<"my true love sent to me:"<<endl;
}
else if(input==12)
{
cout<<"On the twelfth day of Christmas"<<endl;
cout<<"my true love sent to me:"<<endl;
}
switch(input)//determine the choice
{
case 12:
cout<<"12 Drummers Drumming"<<endl;
case 11:
cout<<"Eleven Pipers Piping"<<endl;
case 10:
cout<<"Ten Lords a Leaping"<<endl;
case 9:
cout<<"Nine Ladies Dancing"<<endl;
case 8:
cout<<"Eight Maids a Milking"<<endl;
case 7:
cout<<"Seven Swans a Swimming"<<endl;
case 6:
cout<<"Six Geese a Laying"<<endl;
case 5:
cout<<"Five Golden Rings"<<endl;
case 4:
cout<<"Four Calling Birds"<<endl;
case 3:
cout<<"Three French Hens"<<endl;
case 2:
cout<<"Two Turtle Doves"<<endl;
case 1:
cout<<"and a Partridge in a Pear Tree"<<endl;
break;
case -1://if I type 1 and it'll stop
break;
default://if you type other word it shows the sentence
cout<<"you type wrong"<<endl;
break;
case ' '://it ignores ' '
break;
}
}while(input!=-1);//if input=-1, it'll stop
system("pause");
return 0;
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.7.59