Question: C++ program that asks the user to repeatedly enter positive integers and stop when the user enters -1.If a different negative number (or zero) is

C++

program that asks the user to repeatedly enter positive integers and stop when the user enters -1.If a different negative number (or zero) is entered, the program should output "The number should be a positive integer or -1." and then prompt for the next number.

You need to use a vector in this question. At the beginning of the program, the vector is empty. Then, as the user enters values, the vector will be updated based on the following conditions in this order (1, 2, 3):

1) If the vector is empty, insert the user input value into the vector

2a) If the vector is not empty and the input value is divisible by 5, then remove an element from the front of the vector

2b) If the vector is not empty and the user input value is divisible by 3, then remove an element from the end of the vector

  • Hint: Notice that numbers can be divisible by both 3 and 5!

3) Otherwise, insert the input value at the end of the vector.

After the user is done entering values, your program should display all elements in the vector, in order, separated by spaces. On the next line, it also displays the minimum value and the maximum values in the vector.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!