Exercise 2.1

main() [in Section 2.1] allows the user to enter only one position value and then terminates. If a user wishes to ask for two or more positions, he must execute the program two or more times. Modify main() [in Section 2.1] to allow the user to keep entering positions until he indicates he wishes to stop.

We use a while loop to execute the “solicit position, return value” code sequence. After each iteration, we ask the user whether he wishes to continue. The loop terminates when he answers no. We’ll jump-start the first iteration by setting the bool object more to true.

 #include <iostream> using namespace std; extern bool fibon_elem( int, int& ); int main() { int pos, elem; char ch; bool more = true; while ( more ) { cout << "Please ...

Get Essential C++ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.