#include <iostream>
using namespace std;
int main()
{
int num, greatest, least;
char doAgain;
do
{ cout << "This program lets you input a series of numbers and finds\nthe greatest and least values.\n";
cout << "Type in a value. -99 will finish the series.\n";
cin >> num;
if (num == -99)
cout << "\nNo values were entered, so there is no smallest and greatest value.\n";
greatest = num, least = num;
while (num != -99)
{
if (num > greatest)
greatest = num;
else if (num < least)
least = num;
cout << "Enter another value.\n";
cin >> num;
}
if (greatest != -99 && least != -99)
{ cout << "\nSmallest value: " << least << endl;
cout << "Greatest value: " << greatest << endl;}
cout << "\nWould you like to do this again?(Y/N)\n";
cin >> doAgain;
cout << endl;}
while (doAgain == 'y' || doAgain == 'Y');
return 0;
}
The code asks for a series of integers and when -99(sentinel) is typed in it will find the greatest and smallest values.
The code works as I want, but I need to add a way for num's multiple values to be outputted along with the greatest and smallest values. With the class I'm taking, I've only learned multiple loops, if/else statements/switch, relation/logical operaters, not too complicated things, I've been having trouble writing a simple code that will do this. Huge kudos to anyone that can help or atleast direct me into the right path. This has been killing me for a while not being able to figure it out.