Respuesta :
Answer:
#include <iostream>
#include <string>
// R, R, R, L, L, L, R, L, R, R, L, X ==> 6R 5L X
void getLeftOrRight(std::string &l_or_r, int &total_l, int &total_r) {
// notice how the above line matches: getLeftOrRight(leftOrRight, leftTotal, rightTotal);
// the values provided from the loop are given nicknames for this function getLeftOrRight()
if (l_or_r == "L") { // left-handed
total_l++;
} else if (l_or_r == "R") { // right-handed
total_r++;
} else { // quit
// option must be "X" (quit), so we do nothing!
}
return; // we return nothing, which is why the function is void
}
int main() {
std::string leftOrRight = ""; // L or R for one student.
int rightTotal = 0; // Number of right-handed students.
int leftTotal = 0; // Number of left-handed students.
while (leftOrRight != "X") { // whilst the user hasn't chosen "X" to quit
std::cout << "Pick an option:" << std::endl;
std::cout << "\t[L] left-handed\n\t[R] right-handed\n\t[X] quit\n\t--> ";
std::cin >> leftOrRight; // store the user's option in the variable
getLeftOrRight(leftOrRight, leftTotal, rightTotal); // call a function, and provide it the 3 arguments
}
std::cout << "Number of left-handed students: " << leftTotal << std::endl;
std::cout << "Number of right-handed students: " << rightTotal << std::endl;
return 0;
}
Explanation:
This is my take on the question! I had no idea what was meant by the housekeeping(), detailLoop(), endOfJob() functions provided in their source code.
What my code does should be pretty explanatory via the comments and variable names within it — but feel free to make a comment to ask for more info! I've attached a screenshot of my code because I think it's easier to read when it's syntax highlighted with colors.
