[PHP]#include <iostream>
int main()
{
using std::cout;
using std::endl;
using std::cin;
int value, count=0, sum=0, average,total, smallest, largest;
for(;;) // i.e. loop forever .... until break
{
for(;;) // ever ...
{
cout << "Enter value " << count+1 << ": ";
value = -9999;
cin >> value;
if (value > largest )
largest=value;
cin.clear();
cin.sync();
if ( value == -9999 ) { cout << "Bad data entry ... "; continue; }
if ( value == 9999 ) break; // break out of inner loop
++count;
total= sum += value;
average= total/count;
} // end of inner forever loop ...
if (value == 9999 ) break; // break out of outer loop
} // end of outer forever loop ...
cout << "For " << count << " values entered ...\n"
// << "Smallest = " << smallest << endl
<< "Largest = " << largest << endl
<< "Sum = " << total << endl
<< "Average = " << average << endl;
cout << "\nPress 'Enter' to continue ... ";
cin.get();
}[/PHP]
I have this loop and it's supposed to find the largest # and smallest #, now i found largest, but i want to not include the sentinel 9999 exit loop value, how would i do that. And what would i do to find the smallest, nothing's working =(
int main()
{
using std::cout;
using std::endl;
using std::cin;
int value, count=0, sum=0, average,total, smallest, largest;
for(;;) // i.e. loop forever .... until break
{
for(;;) // ever ...
{
cout << "Enter value " << count+1 << ": ";
value = -9999;
cin >> value;
if (value > largest )
largest=value;
cin.clear();
cin.sync();
if ( value == -9999 ) { cout << "Bad data entry ... "; continue; }
if ( value == 9999 ) break; // break out of inner loop
++count;
total= sum += value;
average= total/count;
} // end of inner forever loop ...
if (value == 9999 ) break; // break out of outer loop
} // end of outer forever loop ...
cout << "For " << count << " values entered ...\n"
// << "Smallest = " << smallest << endl
<< "Largest = " << largest << endl
<< "Sum = " << total << endl
<< "Average = " << average << endl;
cout << "\nPress 'Enter' to continue ... ";
cin.get();
}[/PHP]
I have this loop and it's supposed to find the largest # and smallest #, now i found largest, but i want to not include the sentinel 9999 exit loop value, how would i do that. And what would i do to find the smallest, nothing's working =(
Comment