我似乎无法让它倒数最后一节。我试图创建一个减去 1 的新变量并将该变量放在最后一节中,它适用于除数字 9、19、29、39...99 之外的所有变量。有人可以给我一个提示或指出我正确的方向吗?我还尝试创建另一个循环来倒计时并从数组中读取它。我只学了几个月,不知道还能尝试什么。我想我一旦达到这一点,困难的部分就在我身后,至少对我来说不是那么多。谢谢你。它是 Visual Studio 2010 中的 c++。
#include <iostream>
#include <string>
using namespace std;
string tens[11] = {""," Ten"," Twenty"," Thirty"," Forty"," Fifty"," Sixty"," Seventy"," Eighty"," Ninety"};
string ones[10] = {"","-One","-Two","-Three","-Four","-Five","-Six","-Seven","-Eight","-Nine"};
string s_ones[11] = {" Zero"," One"," Two"," Three"," Four"," Five"," Six"," Seven"," Eight"," Nine"};
string other[ ] = {" Ten"," Eleven"," Twelve"," Thirteen"," Fourteen"," Fifteen"," Sixteen"," Seventeen"," Eighteen"," Nineteen",""};
int main()
{
for(int i = 99; i >= 0; --i)
{
int tens_place = i / 10, ones_place = i % 10, small_ones_place = i % 10;
if(10 <= i && i < 20)
{
cout << other[i - 10] << " bottles of beer on the wall. \n"
<< other[i - 10] << " bottles of beer.\n"
<< " Take one down, pass it around,\n"
<< other[(i - 10)] << " bottles of beer on the wall.\n\n";
}
if(20 <= i && i <= 99)
cout << tens[tens_place] + ones[ones_place] << " bottles of beer on the wall. \n"
<< tens[tens_place] + ones[ones_place] << " bottles of beer.\n"
<< " Take one down, pass it around,\n"
<< tens[tens_place] + ones[ones_place] << " bottles of beer on the wall.\n\n";
if(2 <= i && i < 10)
cout << s_ones[small_ones_place] << " bottles of beer on the wall.\n"
<< s_ones[small_ones_place] << " bottles of beer.\n"
<< " Take one down, pass it around,\n"
<< s_ones[small_ones_place] << " bottles of beer on the wall.\n\n";
if(i == 1)
cout << s_ones[small_ones_place] << " bottle of beer on the wall.\n"
<< s_ones[small_ones_place] << " bottle of beer.\n"
<< " Take one down, pass it around,\n"
<< s_ones[small_ones_place] << " bottles of beer on the wall.\n\n";
if(i == 0)
cout << s_ones[small_ones_place] << " bottles of beer on the wall.\n"
<< s_ones[small_ones_place] << " bottles of beer.\n"
<< " Go to the store and get some more,\n"
<< " Ninety-nine bottles of beer on the wall.\n\n";
}
return(0);
}