This assignment is worth 10 points.
More details can be found in chapter 8 of your book.
// get the starting position cout << "Enter the starting cubits => "; cin >> inputCubits; cout << "Enter the starting palms => "; cin >> inputPalms; cout << "Enter the starting fingers => "; cin >> inputFingers;
startFingers = inputFingers + inputPalms * FINGERS_PER_PALM + inputCubits * PALMS_PER_CUBIT * FINGERS_PER_PALM;
fingers = startFingers % FINGERS_PER_PALM; startFingers /= FINGERS_PER_PALM; palms = startFingers % PALMS_PER_CUBIT; cubits = startFingers / PALMS_PER_CUBIT;
cout << " ended at: " << cubits << " cubits " << palms << " palms " << fingers << " fingers " << endl;
startFingers = inputFingers + inputPalms * FINGERS_PER_PALM + inputCubits * PALMS_PER_CUBIT * FINGERS_PER_PALM;
int ConvertToFingers(int fingers, int palms, int cubits);
const int GRAINS_PER_FINGER{1}; int ConvertToFingers(int fingers, int palms, int cubits); int main() {
int ConvertToFingers(int fingers, int palms, int cubits) { int totalFingers{0}; totalFingers = fingers + palms * FINGERS_PER_PALM + cubits * PALMS_PER_CUBIT * FINGERS_PER_PALM; return totalFingers; }
return 0; } int ConvertToFingers(int fingers, int palms, int cubits) { int totalFingers{0}; totalFingers = fingers + palms * FINGERS_PER_PALM + cubits * PALMS_PER_CUBIT * FINGERS_PER_PALM; return totalFingers; }
startFingers = inputFingers + inputPalms * FINGERS_PER_PALM + inputCubits * PALMS_PER_CUBIT * FINGERS_PER_PALM;
startFingers = ConvertToFingers(inputFingers, inputPalms, inputCubits);
endFingers = inputFingers + inputPalms * FINGERS_PER_PALM + inputCubits * PALMS_PER_CUBIT * FINGERS_PER_PALM;
endFingers = ConvertToFingers(inputFingers, inputPalms, inputCubits);
void GetInput(int & fingers, int & palms, int & cubits, string pos);
void GetInput(int & fingers, int & palms, int & cubits, string pos){ cout << "Enter the " << pos << " cubits => "; cin >> cubits; cout << "Enter the " << pos << " palms => "; cin >> palms; cout << "Enter the " << pos << " fingers => "; cin >> fingers; return; }
cout << "Enter the starting cubits => "; cin >> inputCubits; cout << "Enter the starting palms => "; cin >> inputPalms; cout << "Enter the starting fingers => "; cin >> inputFingers;
GetInput(inputFingers, inputPalms, inputCubits, "starting");
cout << "Enter the ending cubits => "; cin >> inputCubits; cout << "Enter the ending palms => "; cin >> inputPalms; cout << "Enter the ending fingers => "; cin >> inputFingers;
GetInput(inputFingers, inputPalms, inputCubits, "ending");
ReduceFingers(int totalFingers, int & fingers, int & palms, int & cubits);
void ReduceFingers(int totalFingers, int & fingers, int & palms, int & cubits){ fingers = totalFingers % FINGERS_PER_PALM; totalFingers /= FINGERS_PER_PALM; palms = totalFingers % PALMS_PER_CUBIT; cubits = totalFingers / PALMS_PER_CUBIT; return; }
fingers = startFingers % FINGERS_PER_PALM; startFingers /= FINGERS_PER_PALM; palms = startFingers % PALMS_PER_CUBIT; cubits = startFingers / PALMS_PER_CUBIT;
ReduceFingers(startFingers, fingers, palms, cubits);
void PrintUnits(int fingers, int palms, int cubits);
void PrintUnits(int fingers, int palms, int cubits){ cout << cubits << " cubits " << palms << " palms " << fingers << " fingers"; return; }
cout << "Nebi and Ako started at: " << cubits << " cubits " << palms << " palms " << fingers << " fingers " << endl;
cout << "Nebi and Ako started at: "; PrintUnits(fingers, palms, cubits); cout << endl;