2013-04-24 4 views
0

선생님은 계속해서 수정해야 할 항목과 같은 줄에 setw가 있어야한다는 말을 계속한다. 나는 그랬다고 생각했지만 그녀는 계속 그 사실을 알리고 계속해서 그녀가 내 매개 변수에 잘못을 표시했기 때문에 다른 사람이 내 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 
*/ 
+2

'setw (3)'이 (가) 무엇을하고 있다고 생각하십니까? –

+0

또한 main _does_는 반환 값이 –

+0

입니다. array [i] 앞에 3 개의 공백 집합을 설정하고 있음을 확신합니다. – Geoff

답변

1

여기에 some documentation for std::setw입니다. 링크에서

: 식 out << setw(n)에 사용

는 ..., N에 정확히 스트림 중에 또는 폭 파라미터를 설정한다.

그래서 당신의 라인 :

cout<<"*"<<setw(4)<<i<<setw(3); 

는이 순서에서 이런 일을 않습니다

  • 인쇄 "*"
  • 의 폭을 설정 cout지금-4
  • 사용합니다 4
  • 의 폭
  • 인쇄는 i 폭이 cout지금 선생님이하지 않는 3.

    의 폭을해야합니다 당신은 그 후 인쇄 무엇이든 3

를 사용 설정 그것이 불분명 한 것 같습니다. 은 너비가 3으로 인쇄 될 것입니다. 다음에 인쇄되는 것은 다른 줄에 있기 때문입니다.

관련 문제