Okay after burning midnight and daytime oil I finally finished my code. It's working like a charm.
I just have a question though.
How does the boolean work?
Meaning, the results show if ANY of the numbers were within a range ..either
< 20
and between 10-90.
Where is this kept track of?? Everytime it loops and the answer is either true or false, is there a memory bank in which all the iterations are stored to tell the user that a certain amount of numbers are in a range?? After looking at it, I would just think that the LAST input would show up as in a range UNLESS bool works or something else works as a memory storage to to keep track of each iteration and of how many are in the range...
Can anyone answer this for me??
Ill post my code if this explanation makes NO sense......:)
Thanks!!1
CODE
namespace std;
int main(int argc, char *argv[])
{
int x;
int sum =0;
int test_count = 1;
double average;
int smallest= INT_MAX;
int largest= INT_MIN;
bool less20 = false;
bool range = false;
cout << " Enter your numbers: then 9999 to stop.\n";
cin >> x;
while (x != 9999)
{
if (x < 20)
less20 = true; // Does this line act as a memory bank to keep track of how many are < 20.
if ( x > 10 && x < 90)
range = true;
sum += x;
if ( x < smallest )
smallest = x;
if ( x > largest)
largest = x;
cout << "\n";
test_count++;
cin >> x;
}
cout << "\nThe total is: " <<sum << endl;
cout<< "\nNumber of integers: "<< test_count -1<< endl;
cout<< "\n";
average = 1.0 * sum/ test_count;
cout<< "Average is: " << average << "\n";
cout<< "\n";
cout<< "The smallest number is: " << smallest<< "\n";
cout<<"\n";
cout<< "The largest number is: " << largest<< "\n";
cout<<"\n";
cout<< "Numbers less than 20? ";
if (less20)
cout<< "true\n";
else
cout<< "false\n";
cout<< " Are all numbers within the range 10-90 ";
if (range)
cout<<"true\n";
else
cout<< "false\n";
system("PAUSE");
return 0;
}