Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

What do you mean by 'make or buy decision ' ?

Answered: 1 week ago