Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

why it did not compile and run? please, can you fix the error #include #include using namespace std; // FUNCTION PROTOTYPES GO HERE: int numPegs(const

why it did not compile and run? please, can you fix the error

#include #include

using namespace std;

// FUNCTION PROTOTYPES GO HERE: int numPegs(const int size, int n);

void readNum(int d[], int peg, const int max);

int checkMax(int i, int n, const int max);

void drawRods(int d[], int peg);

void printPercentage(int numD, int peg, int total);

void displayStatistics(int d[], int peg);

void getSmall(int d[], int peg);

void getLarge(int d[], int peg);

void getAverage(int d[], int peg);

bool checkZero(int d[], int peg);

void play(int d[], int peg, int pId, int& pegChoose, int& numRemove);

int pegChoos(int pId);

void vailPegChoose(int pId, int& pegChoose, int peg);

void vailDiscs(int d[], int pId, int pegChoose);

int vailRemoveDiscs(int numD, int pegChoose);

void removeDiscs(int d[], int pegChoose, int numRemove);

void printWinner(int pId);

void changePlayer(int& pId);

int main() { // Define variables and constants here const int SIZE = 15; const int max = 10; int peg = 0; int d[SIZE]; int pId = 1; int pegChoose = 0; int numRemove = 0; int n = 0;

// Algorithm:

// Prompt and read number of rods cout<<"How many pegs are in this game? "; cin>>n; peg = numPegs(SIZE, n);

// Prompt and read the number of objects in each rod

readNum(d, peg, max);

// Draw the rods with percentages

drawRods(d, peg);

// Display statistics

displayStatistics(d, peg);

// WHILE some rod is NOT empty DO

while(checkZero == false){

// Prompt and read the next player's move

play(d, peg, pId, pegChoose, numRemove);

// Remove the specified number of objects from the specified rods

removeDiscs(d, pegChoose, numRemove);

// IF all the heaps are empty, THEN

if(checkZero==false){

// Print a message congratulating the winning player.

printWinner(pId);

// ELSE

}else{

// Redraw the rods with percentages

drawRods(d, peg);

// Display statistics

displayStatistics(d, peg);

// Change to the other player changePlayer(pId);

// END IF

}

// END WHILE

}

return 0; }

// FUNCTION DEFINITIONS GO HERE:

int numPegs(const int size, int n){ while(n>size||n<0){ cout<<"Number of pegs must be positive and less than or equal to "<>n; } return n; }

void readNum(int d[], int peg, const int max){

int n = 0; for(int i = 0; i>n; d[i] = checkMax(i, n, max); }

}

int checkMax(int i,int n, const int max){

while(n>max||n<0){ cout<<"Sorry, the number of discs must be positive and less than or equal to "<>n; } return n; }

void drawRods(int d[], int peg){

int total = 0; for(int i = 0; i

}

void printPercentage(int numD, int peg, int total){

double avg = 0.0; avg = (double)(numD/total)*100; cout<<"("<

}

void displayStatistics(int d[], int peg){

getSmall(d, peg); getLarge(d, peg); getAverage(d, peg);

}

void getSmall(int d[], int peg){

int s = d[0]; for(int i = 0; i

}

void getLarge(int d[], int peg){

int l = d[0]; for(int i = 0; il){ l = d[i]; } } for(int j = 0; j

}

void getAverage(int d[], int peg){

double avg = 0.0; int total = 0; for(int i = 0; i

}

bool checkZero(int d[], int peg){

int j = 0; for(int i = 0; i

if(d[i]==0){ j = j+1; }

} if(j = peg){ return true; }else{ return false; }

}

void play(int d[], int peg, int pId, int& pegChoose, int& numRemove){

vailPegChoose(pId, pegChoose, peg); vailDiscs(d, pId, pegChoose); while(numRemove>d[pegChoose] || numRemove<0){ numRemove = vailRemoveDiscs(d[pegChoose], pegChoose); }

}

int pegChoos(int pId){

int n = 0; cout<<"Player ("<>n; return n;

}

void vailPegChoose(int pId, int& pegChoose, int peg){

while(pegChoose<0 || pegchoose>(peg-1)){

pegChoose = pegChoos(pId); }

}

void vailDiscs(int d[], int pId, int& pegChoose){

while(d[pegChoose]<1){

pegChoose = pegChoos(pId); }

}

int vailRemoveDiscs(int numD, int pegChoose){

int n = 0; cout<<"Enter number of discs to remove "<>n; return n;

}

void removeDiscs(int d[], int pegChoose, int numRemove){

d[pegChoose] = d[pegChoose] - numRemove;

}

void printWinner(int pId){ cout<<"Congratulations! Player "<

void changePlayer(int& pId){ if(pId == 1){ pId = 2; }else{ pId = 1; } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases DeMYSTiFieD

Authors: Andy Oppel

2nd Edition

0071747990, 978-0071747998

More Books

Students also viewed these Databases questions

Question

8.1 Differentiate between onboarding and training.

Answered: 1 week ago

Question

8.3 Describe special considerations for onboarding.

Answered: 1 week ago