2

私はそれを最後の詩でカウントダウンさせることができないようです。私は1を引いてその変数を最後の詩に入れる新しい変数を作成しようとしました、そしてそれは数9、19、29、39...99を除いてすべてのために働きます。誰かが私にヒントを与えるか、正しい方向に私を向けることができますか?また、カウントダウンして配列から読み取るための別のループを作成してみました。私はこれを数ヶ月しか学んでおらず、他に何を試すべきかわかりません。この時点に到達すると、少なくとも私にとって難しい部分は、それほどではなく、私の後ろにあると思いました。ありがとうございました。VisualStudio2010では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);
}
4

1 に答える 1

1

正しく動作するようになります。あなたがしなければならないのは、最後の行の自分の場所のインデックスから1を引くことです。このような:

<< " Take one down, pass it around,\n"
<< other[(i - 10)-1] << " bottles of beer on the wall.\n\n";
于 2012-11-23T22:00:12.410 に答える