1

このコードを書いているときに別の問題に遭遇しました (ここのプログラマーからの多くの助けを借りて)。正しい値を出力するプログラムに問題があります。beadArrayTop は次のようなものを出力するはずです。

 4   *    4    *   4   *   4   *   4   *   4    *

代わりに、4 があるべき場所に 0 のみを出力します。

beadArrayBottom はほとんど同じことを行います。関数 printArray を beadArrayTop と beadArrayBottom の前に配置しようとしました。さらに、beadArrayTop と beadArrayBottom を printArray の中に配置しようとしましたが、役に立ちませんでした。出力を正しくするために何をすべきかについてのヒントはありますか? コードは次のとおりです。

    #include <iostream>
#include <iomanip>



using namespace std;

const int MAX = 14;
void line (int &cycleCounter, int &starCounter); //outputs a star followed by six spaces
void solidLine (); //outputs a solid line of stars
void smallerLine (); //ouputs a smaller line of stars
void board (); //outputs the mancala board, with numbers indicating the bins.
void binNumbersTop (); //outputs numbers indicating the bin # (Top only).
void binNumbersBottom (); //outputs numbers indicating the bin # (Bottom only).
void beadArrayTop (); //outputs the array for the top.
void beadArrayBottom (); //outputs the array for the bottom.
void beadArrayMiddle (); //outputs the array for the end bins.
void startArray (int beadArray [MAX]); //Creates an array of 14, with 4 in every slot except for 6 and 13.
void printArray (); //Outputs the array mentioned above
int beadArray[MAX];



int main ()

{





    board ();
    cout<<endl;












    cout<<endl;
    system("pause");
    return 0;




}


//**********************************************//
void line ()
{
    int cycleCounter = 9;
    int starCounter = 6;

    while (cycleCounter > 0)
    {
        cout<<"*";


        int spaceCounter = 1;

        while (spaceCounter > 0)
        {
            cout<<"      ";
            spaceCounter = spaceCounter - 1;
            starCounter = starCounter - 1;
            cycleCounter = cycleCounter - 1;
        }
    }
}

//************************************************//
void solidLine()

{
    int loopCounter;
    loopCounter = 57;

    while (loopCounter > 0)
    {
        cout<<"*";
        loopCounter = loopCounter - 1;
    }

}   
//************************************************//
void smallerLine ()
{
    int loopCounterTwo;
    loopCounterTwo = 43;
    cout<<"*  13  ";
    while (loopCounterTwo > 0)
    {
        cout<<"*";
        loopCounterTwo = loopCounterTwo - 1;
    }
    cout<<"   6  *";
}   
//************************************************//
void binNumbersTop ()
{
    cout<<"*";
    int topNumbers = 1;
    cout << setw (7)<<"*";
    cout <<setw (4)<< 0;
    cout << setw (3)<<"*";

    while (topNumbers < 6)
    {
        cout <<setw (4)<< topNumbers;
        cout <<setw (3)<<"*";
        topNumbers = topNumbers + 1;
    }

    cout << setw (7)<<"*"<<endl;

}


//**********************************************//
void binNumbersBottom ()
{
    cout<<"*";
    int bottomNumbers = 11;
    cout << setw (7)<<"*";
    cout <<setw (4)<< 12;
    cout << setw (3)<<"*";

    while (bottomNumbers >= 7)
    {
        cout <<setw (4)<< bottomNumbers;
        cout <<setw (3)<<"*";
        bottomNumbers = bottomNumbers - 1;
    }

    cout << setw (7)<<"*"<<endl;

}

//**********************************************//

void beadArrayTop ()
{

    cout<<"*";
    cout <<setw (7)<<"*";
    cout <<setw (4) <<beadArray[0];
    cout <<setw (3) <<"*";
    cout <<setw (4) <<beadArray[1];
    cout <<setw (3) <<"*";
    cout <<setw (4) <<beadArray[2];
    cout <<setw (3) <<"*";
    cout <<setw (4) <<beadArray[3];
    cout <<setw (3) <<"*";
    cout <<setw (4) <<beadArray[4];
    cout <<setw (3) <<"*";
    cout <<setw (4) <<beadArray[5];
    cout <<setw (3) <<"*";
    cout <<setw (7) <<"*";

}
//***********************************************//
void beadArrayBottom ()
{

    cout<<"*";
    cout <<setw (4)<<beadArray[13];
    cout <<setw (3)<<"*";
    cout <<setw (4) <<beadArray[12];
    cout <<setw (3) <<"*";
    cout <<setw (4) <<beadArray[11];
    cout <<setw (3) <<"*";
    cout <<setw (4) <<beadArray[10];
    cout <<setw (3) <<"*";
    cout <<setw (4) <<beadArray[9];
    cout <<setw (3) <<"*";
    cout <<setw (4) <<beadArray[8];
    cout <<setw (3) <<"*";
    cout <<setw (4) <<beadArray[7];
    cout <<setw (3) <<"*";
    cout <<setw (4) <<beadArray[6];
    cout<< setw (3) <<"*";

}
//***********************************************//

void board ()
{



solidLine ();
cout<<endl;


line ();
cout<<endl;



binNumbersTop ();


line ();
cout<<endl;
beadArrayTop ();

cout<<endl;
line ();
cout<<endl;


smallerLine();
cout<<endl;
line ();
cout<<endl;


binNumbersBottom ();


line ();
cout<<endl;
beadArrayBottom ();
cout<<endl;
line ();
cout<<endl;





solidLine ();
cout<<endl;


}

//*********************************************//

void startArray (int beadArray[MAX])
{
    for(int i=0; i<MAX; ++i)
    {
        beadArray[i]=4;
    }
    beadArray[6]=0;
    beadArray[13]=0;
}
//*********************************************//
void printArray ()
{
    startArray (beadArray);
    for(int i=0; i<MAX; i++)
    cout << beadArray[i];
    cout<<endl<<endl;
}
//*********************************************//
4

2 に答える 2