私の先生は、変更されている項目と同じ行に setw を配置する必要があると私に言い続けています。私はやったと思っていましたが、彼女はそうではないと言い続け、パラメータに間違ったラベルを付けていると言い続けています。各関数の下のコメントに、パラメーターのラベルを付けます。
#include <iostream>
#include <iomanip>
using namespace std;
const int MAX=14;
void startArray(int beadArray[MAX]);//Creates the array that gets printed out
void printArray(int beadArray[MAX]);//Prints out the array
void board(int beadArray[MAX]); //Creates the board out of stars
void makeSolidLine(int numStars); //makeSolidLine makes a line out of numStars
void line(); // A line of stars with 6 spaces inbetween
void topBinNum(); //Numbers in top of the board
void bottomBinNum(); //Numbers in the bottom bin
void topBinNumValue(); //Values of each slot in the top bin
void bottomBinNumValue(); //Values of each slot in the bottom bin
int gameOver(int beadArray[MAX]); //Declares the winner by adding bins and comparing the totals
int main()
{
int beadArray[MAX];
startArray(beadArray);
board(beadArray);
int winner;
winner=gameOver(beadArray);
cout<<winner;
system("pause");
return 0;
}
/*Calls the functions in proper order so the code will run smoothly
parameter=n/a
return value=n/a
*/
void topBinNum()
{
cout<<"* ";
for(int i=0; i<6; i++)
{
cout<<"*"<<setw(4)<<i<<setw(3);
}
cout<<"*";
cout<<" *\n";
}
/*Numbers the slots on the board starting at 0 setting spaces and a * between slots then moving to the next slot adding 1 and so on until at 5 then it stops
parameter=n/a
return value=n/a
*/
void bottomBinNum()
{
cout<<"* ";
for(int i=12; i>6; i--)
{
cout<<"*"<<setw(4)<<i<<setw(3);
}
cout<<"*";
cout<<" *\n";
}
/*Numbers the slots on the board starting at 12 setting spaces and a * between slots then moving to the next slot subtracting 1 and so on until at 7 then it stops
parameter=n/a
return value=n/a
*/
void makeSolidLine(int numStars)
{
for (int count=0; count<numStars; count++)
{
cout<<"*";
}
}
/*Prints out a solid line of *
parameter=int numStars
return value=n/a
*/
void line()
{
for (int count=0; count<8; count++)
{
cout<<"*";
for(int count=0; count<6; count++)
{
cout<<" ";
}
}
cout<<"*\n";
}
/*Prints out a line of * with six spaces inbetween
parameter=n/a
return value=n/a
*/
void startArray (int beadArray[MAX])
{
for(int i=0; i<MAX; ++i)
{
beadArray[i]=4;
}
beadArray[6]=0;
beadArray[13]=0;
}
/*gives each slot a value
parameter=int beadArray[MAX]) keeps array from going above the MAX
return value=n/a
*/
void printArray (int beadArray[MAX])
{
for(int i=0; i<MAX; i++)
{
cout<<beadArray[i];
cout<<endl<<endl;
}
}
/*Finds data needed to print out the numbers in the correct order
parameter=int beadArray[MAX] keeps array from going above the MAX
return value=n/a
*/
void topBinNumValue(int beadArray[MAX])
{
cout<<"* ";
for(int i=0; i<6; i++)
{
cout<<"*"<<setw(4)<<beadArray[i]<<setw(3);
}
cout<<"*";
cout<<" *\n";
}
/*
topBinNumValue calls the parameter int beadArray[MAX] which is the slot scores from 0-4 and outputs five 4's with no return value
parameter=int beadArray[MAX] keeps array from going above the MAX
return value=n/a
*/
void bottomBinNumValue(int beadArray[MAX])
{
for(int i=13; i>5; i--)
{
cout<<"*"<<setw(4)<<beadArray[i] <<setw(3);
}
cout<<" *\n";
}
/*
bottomBinNumValue calls the parameter int bead array[max] which is the slot scores from 6-13 and outputs a 0 then five 4's and another 0 with no return value
parameter=int beadArray[max] keeps array from going above the MAX
return value=n/a
*/
void board(int beadArray[MAX])
{
makeSolidLine(57);
cout<<endl;
line();
topBinNum();
line();
topBinNumValue(beadArray);
line();
cout<<"* 13 ";
makeSolidLine(43);
cout<<" 6 *";
cout<<endl;
line();
bottomBinNum();
line();
bottomBinNumValue(beadArray);
line();
makeSolidLine(57);
cout<<endl;
}
/*Creates the board with numbers in proper location by calling all the previously created codes the print out the board.
parameter=int beadArray[MAX] keeps array from going above the MAX
return value=n/a
*/
int gameOver(int beadArray[MAX])
{
int total1=0;
int total2=0;
int winner=0;
for(int i=0; i<6; i++)
{
total1=total1+beadArray[i];
}
for(int i=12; i>6; i--)
{
total2=total2+beadArray[i];
}
if(total1==0||total2==0)
{
if(total1>total2)
{
winner =1;
}
else
{
winner=2;
}
}
else
{
winner= -1;
}
return winner;
}
/*Adds the totals to beadArray[13 & 6] checks to see which slot is higher and displays the winner if there is one.
parameter=int beadArray[MAX] keeps array from going above the MAX
return value=winner, who ever won the game is the return value
*/