Question
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
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 "<
void readNum(int d[], int peg, const int max){
int n = 0; for(int i = 0; i
}
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 "<
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; i } 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 ("< } 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 "< } 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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started