C++ Board Landing Function for Board Game: mostLandings ? returns the cell on th
ID: 662712 • Letter: C
Question
C++ Board Landing Function for Board Game:
mostLandings
? returns the cell on the board with the most "landings", within an inclusive interval
? parameters: a vector<int>; two integers
? first parameter: the game board vector, by const reference
? second parameter: the start of the interval to be tested, by value
? third parameter: the end of the interval to be tested, by value
? return type: integer, the index of the first cell in the interval with the most landings
How do I code for this if this function returns the cell with most landings within a closed interval of board spots. (The closed interval [5,10] means any of the values 5, 6, 7, 8, 9, or 10.) As your player traverses the board, you will record each cell he/she lands on. You will performmultiple simulations of a single board rotation, accumulating in each vector cell the number of times the player lands on the corresponding board space.
My code so far is declaring parameters but I don't know how to go from there:
int mostLandings(vector<int> &board, int intOne, int intFinal) //intOne being start of interval and intFinal being the end
{
// need code here
}
Explanation / Answer
int mostLandings(vector<int> &board, int intOne, int intFinal){
int mostLandings=0;
int cellPosition=0;
for(int i=intOne;i<=intFinal;i++){
if(board.at(i)>mostLandings){
mostLandings=board.at(i); //find the cell ith most landing
cellPosition=i; //store the cell position with most landing
}
}
return cellPosition; //return the cell with most landing
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.