Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that does this: Prompts the user to input a number. As long as t

ID: 3639424 • Letter: W

Question

Write a program that does this:

Prompts the user to input a number. As long as the user doesn't input the number 0 (zero), continue to ask for more numbers

When the user inputs 0 (zero), ,print out the smallest number entered by the user, and the largest number entered by the user. Note: the 0 shouldn't be considered as one of the user's numbers.

Hint: You do not need to remember (store) all of the numbers the user enters.

Sample Run:

Sample Run1:
Enter a number (0 to endl) -> 5
Enter a number (0 to endl) -> 42
Enter a number (0 to endl) -> -10
Enter a number (0 to endl) -> -3
Enter a number (0 to endl) -> 0
The largest value was 42
the smallest value was -10

Explanation / Answer

Here's the C++ version. Just ran and tested and works perfecly.  Also, using "void main" is generally not good pratice.
*******************************

#include<iostream>
using namespace std;

int main()
{
int n,min,max;

cout << "Enter a number (0 to endl): ";
cin >> n;

max = n;
min = n;

while(n!=0)
{
if(n > max)
max = n;

if(n < min)
min = n;

cout << "Enter a number (0 to endl): ";
cin >> n;
}

cout << "Largest value: " << max << endl;
cout << "Smallest value: " << min << endl;


return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote