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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started