C++
The problem is as below:
The Greatest and Least of These
Write a program with a loop that lets the user enter a series of integers. The user should enter -99 to signal the end of the series. After all the numbers have been entered, the program should display the largest and smallest numbers entered.
#include <iostream> using namespace std; int main() { int min = 0, max = 0, count = 0, num; while (true) { cout << "Enter a number (-99 to exit): "; cin >> num; if (num == -99) break; if (count == 0 || num > max) max = num; if (count == 0 || num < min) min = num; ++count; } cout << "Largest number entered: " << max << endl; cout << "Smallest number entered: " << min << endl; return 0; }
Get Answers For Free
Most questions answered within 1 hours.