用Dev C++写一个程序,急...在线等..

Writeaprogramthatoutputsthelyricsforthesong"Ninety_NineBottlesofBeerontheWall."Yourpr... Write a program that outputs the lyrics for the song "Ninety_Nine Bottles of Beer on the Wall." Your program should print the number of bottles in English, not as a number. For example:
Ninety_nine bottles of beer on the wall,
Ninety-nine bottles of beer,
Take one down, pass it around, Ninety-eight bottles of beer on the wall.
.....
.....
One bottle of beer on the wall,
one bottle of bber,
Take one down, pass it around,
Zero bottles of beer on the wall.

Design your program with a function that takes as an argument an integer between 0 and 99 and returns a string that contains the integer value in English. Your function should bot have 100 different if-else statements@ Instead, use % and / to extract the tens and ones digits to construct the English string. You may need to test specifically for values such as 0, 10-19, etc.

哪位能帮我写一下这个程序,内容不是很难,但是不知道要怎么写...在线等啊...急要...
翻译一下:
写一个程序,运行之后可以output一首歌的歌词:
Ninety_nine bottles of beer on the wall,
Ninety-nine bottles of beer,
Take one down, pass it around,
Ninety-eight bottles of beer on the wall.
.....
.....
One bottle of beer on the wall,
one bottle of bber,
Take one down, pass it around,
Zero bottles of beer on the wall.

歌词都是一样的,就是前面的数字不一样,一直从ninety-nine唱到zero,而且不要数字,是要英文单词来代替数字的,顺便补充一下,不能用100个if else或者case什么的..要用%和/来弄数字..

哪位高手能帮帮忙啊..在线等啊..
展开
 我来答
快EVER乐
2009-04-02 · TA获得超过162个赞
知道小有建树答主
回答量:152
采纳率:0%
帮助的人:113万
展开全部
#include <iostream>
using namespace std;
int getEn(int i)
{
int j = i%10;
int k = i/10;
if(k > 1)
{
switch(k)
{
case 2:
cout << "Twenty";
break;
case 3:
cout << "Thirty";
break;
case 4:
cout << "Forty";
break;
case 5:
cout << "fifty";
break;
case 6:
cout << "Sixty";
break;
case 7:
cout << "Seventy";
break;
case 8:
cout << "Eighty";
break;
case 9:
cout << "Nighty";
break;
}
switch(j)
{
case 1:
cout << "-one";
break;
case 2:
cout << "-two";
break;
case 3:
cout << "-three";
break;
case 4:
cout << "-four";
break;
case 5:
cout << "-five";
break;
case 6:
cout << "-six";
break;
case 7:
cout << "-seven";
break;
case 8:
cout << "-eight";
break;
case 9:
cout << "-night";
break;
}
}
else if(k==1)
{
switch(j)
{
case 0:
cout << "Ten";
break;
case 1:
cout << "Eleven";
break;
case 2:
cout << "Twelve";
break;
case 3:
cout << "Thirteen";
break;
case 4:
cout << "Fourteen";
break;
case 5:
cout << "Fifteen";
break;
case 6:
cout << "Sixteen";
break;
case 7:
cout << "Seventeen";
break;
case 8:
cout << "Eighteen";
break;
case 9:
cout << "Nighteen";
break;
}
}
else if(k==0)
{
switch(j)
{
case 0:
cout << "Zero";
break;
case 1:
cout << "One";
break;
case 2:
cout << "Two";
break;
case 3:
cout << "Three";
break;
case 4:
cout << "Four";
break;
case 5:
cout << "Five";
break;
case 6:
cout << "Six";
break;
case 7:
cout << "Seven";
break;
case 8:
cout << "Eight";
break;
case 9:
cout << "Night";
break;
}
}
return 1;
}
int main()
{
for(int i=99;i>0;i--)
{
getEn(i);
cout << " bottles of beer on the wall," << endl;
getEn(i);
cout << " bottles of beer." << endl << "Take one down, pass it around." << endl;
}
getEn(0);
cout << " bottles of beer on the wall," << endl;
getEn(0);
cout << " bottles of beer." << endl;
system("pause");
}

我这种写法很适合初学者,呵呵
心中风情4
2009-04-02 · TA获得超过2247个赞
知道大有可为答主
回答量:1779
采纳率:66%
帮助的人:1078万
展开全部
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;

const char * num_low[] = {"one","two","three","four","five","six","seven","eight","nine"};
const char * num_0_9[] = {"Zero","One","Two","Three","Four","Five","Six","Seven","Eight","Nine"};
const char * num_high[] = {"Twenty","Thirty","Forty","Fifty","Sixty","Seventy","Eighty","Ninety"};
const char * num_10_19[] = {"Ten","Eleven","Twelve","Thirteen","Fourteen","Fifteen","Sixteen","Seventeen", "Eighteen", "Nineteen"};
string getNumString(int n)
{
int high = n/10;
if(high == 0) return string(num_0_9[n]);

int low = n%10;
if(high == 1) return string(num_10_19[low]);

string res = string(num_high[high-2]);
if(low != 0)
{
res += "-";
res += num_low[low-1];
}

return res;
}

void writeLyrics(int n)
{
if(n>99) return;
cout<<getNumString(n)<< " ";
cout<<"bottle";
if(n>1) cout<<"s";
cout<<" of beer on the wall,"<<endl;

cout<<getNumString(n)<< " ";
cout<<"bottle";
if(n>1) cout<<"s";
cout<<" of beer,"<<endl;

cout<<"Take one down, pass it around, "<<endl;
cout<<getNumString(--n)<< " ";
cout<<"bottle";
if(n>1) cout<<"s";
cout<<" of beer on the wall."<<endl;

cout<<endl;

if(n > 0) writeLyrics(n);
}

int main(int argc, char *argv[])
{
int n;
cout<<"Input a number:";
cin>>n;
cout<<endl;
writeLyrics(n);
system("PAUSE");
return EXIT_SUCCESS;
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
百度网友7822fe6
2009-04-02 · TA获得超过1251个赞
知道小有建树答主
回答量:2656
采纳率:0%
帮助的人:1396万
展开全部
这个程序倒是不难,但是真的需要时间的。只有分数恐怕解决不了问题吧。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式