Write a program that uses a while loop to do the following: Repeatedly asks the user to enter a number or -1 to exit the program. Keeps track of the smallest and largest numbers entered so far: You will need a variable for the smallest number and another variable for the largest number. Read the first number the user enters, and if it is not -1 set the smallest and largest variables to that number. Use a loop to gather the remaining input. Each time the user enters a new number that is not -1, compare it to the variables and update them if necessary. When the user enters -1, display the smallest and largest numbers that the user entered. If the user did not enter any numbers before entering -1, then simply exit the program. Run the program and test it on several different sets of values to see if it works. Modify the program to ask the user how many numbers they wish to enter and use a for loop to ask for that many numbers. The sentinel value of -1 should no longer be necessary.

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter5: Repetition Statements
Section: Chapter Questions
Problem 9PP
icon
Related questions
Question
Write a program that uses a while loop to do the following:
Repeatedly asks the user to enter a number or -1 to exit the program.
Keeps track of the smallest and largest numbers entered so far:
You will need a variable for the smallest number and another variable
for the largest number.
Read the first number the user enters, and if it is not -1 set the smallest
and largest variables to that number.
Use a loop to gather the remaining input. Each time the user enters a
new number that is not -1, compare it to the variables and update them
if necessary.
When the user enters -1, display the smallest and largest numbers that the user
entered. If the user did not enter any numbers before entering -1, then simply
exit the program.
Run the program and test it on several different sets of values to see if it works.
Modify the program to ask the user how many numbers they wish to enter and use a
for loop to ask for that many numbers. The sentinel value of -1 should no longer be
necessary.
Transcribed Image Text:Write a program that uses a while loop to do the following: Repeatedly asks the user to enter a number or -1 to exit the program. Keeps track of the smallest and largest numbers entered so far: You will need a variable for the smallest number and another variable for the largest number. Read the first number the user enters, and if it is not -1 set the smallest and largest variables to that number. Use a loop to gather the remaining input. Each time the user enters a new number that is not -1, compare it to the variables and update them if necessary. When the user enters -1, display the smallest and largest numbers that the user entered. If the user did not enter any numbers before entering -1, then simply exit the program. Run the program and test it on several different sets of values to see if it works. Modify the program to ask the user how many numbers they wish to enter and use a for loop to ask for that many numbers. The sentinel value of -1 should no longer be necessary.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Basics of loop
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage