
New assignment.
Please help, running out of time. Assignment is attached. What I have so far is below. Where I am stuck is the "Range" ordeal. Please help:
Code:
#include <iostream>
using namespace std;
//Write a program that reads a series of numbers (doubles) from the user, then prints the mean and the
//range.
//Notes:
//• You do not know ahead of time how many numbers will be in the list.
//• When you want to stop entering numbers, enter controlz.
//• The range is the difference between the lowest and the highest number.
//• The numbers will be in the range of 0.0 to 100.0. Ignore any numbers outside of this range.
int main()
{
double n, count=0, sum=0;
for (;;)
{
if( cin.eof( ) ) break;
while (cin >> n)
if (n <0  n >100){
cout << "out of range; ignored." << endl;
}
else {
++count;
sum += n;
}
}
cout << "The average is " << float (sum)/count << endl;
}

To find the difference between the lowest and the highest number, you must know what they are. If I give you ten numbers, one at a time, and then at the end ask you for the lowest and the highest, what are you going to do to answer my question?

>> Where I am stuck is the "Range" ordeal.
Well, what sort of 'ordeal' are you having with it, exactly?

I know the program I posted works perfectly. The problem I am having is adding the fact of:
"The range is the difference between the lowest and the highest number"
I have to add this programming to my program, and I am really lost with the xmin an xmax stuff?
What it is asking me to do is have the range at bottom under the average:
cout << "The range is " << range ;
The "range" is the difference from the lowest and highest numbers entered. So if you enter 50 different numbers, you need to auto calculate the lowest number entered, to the highest number entered. Max#  Min# = Range.
Need help adding that to my program.

Set 'min' to the lowest possible value. Set 'max' to the highest possible value. On each iteration of the loop, compare these with the input and reassign them if they are exceeded. After the loop, subtract and print.
For obtaining the min/max possible value of a number you can std::numeric_limits (header: <limits>), eg: std::numeric_limits< double >::min( ), etc.

Can you give me an example of this in code?
I really don't know where to begin with all the set / min/max?

What part doesn't make sense to you? Post an attempt to get it working, and then go from there.

I am unsure how to use the set command with the min/max, and unsure how to implement it so it only shows the difference of the lowest and highest numbers entered. Did you see the attachment on my first post? It explains what I am talking about. the assignment is due today and I am soooo struggling.
for example:
if you enter:
1.11
2.22
3.33
4.44
5.55
^z
The average is 3.33 (I am good up to this point)
The range is 4.44 (this is where I am stuck)
To Calculate the range, it is using the highest number entered 5.55 and subtracting the lowest number entered 1.11 = 4.44, but it has to know and only use the min and max numbers no matter what order, for example:
4.44
2.22
1.11
3.33
5.55
It would still only use 1.11 as min and 5.55 as max.
Can you show me an example of code to do this? (Actual code) or help me implement this into my existing code?
I would sincerely appreciate it.

Again, you need to at least make an attempt to do this yourself. Write some code, post it here if you run into any problems, and we'll be glad to point you in the right direction.

Outside the loop create variables min and max. Set min to 100 and max to 0 since this is the range of input you allow.
Inside the loop, for each input, if the input is greater than max set max to the number. This way, when you're done with the loop max will hold the biggest number you've seen so far.
Likewise, if the input is less than min, set min to that input.
After the loop, print min subtracted from max.
Also, in your original code, count should be an integer. There's also no point in casting sum to a float in the output line.

thank you for your help.
so, in my first line I should:
double n, count=0, sum=0, min=100, max=0;
(Is this right?)
Then with each loop do:
if (n > max) max=n
if (n < min) min = n
Is this right?
Also, what do ya mean about:
"Also, in your original code, count should be an integer. There's also no point in casting sum to a float in the output line. "
I am very new to C++, no experience at all.

Yep, that look about right. You should post the entire program, as well (be sure to use code tags and indent your code). Oh, and I was actually backwards about the initialization, eg. min should be set high and max set low, but anyway, it looks like you've got that straight.

Or do I do:
if (n<min) min = n;
else if (n>max) max = n;
And if so, where would I place this in my code?

>> Or do I do:
No. They should be treated separately.
>> And if so, where would I place this in my code?
Inside the loop, of course.

Ok, so will this work? (don't have a compiler on this computer)
Code:
#include <iostream>
using namespace std;
int main()
{
double n, count=0, sum=0, min=0, max=100;
for (;;)
{
if( cin.eof( ) ) break;
while (cin >> n)
if (n<min) min = n;
if (n>max) max = n;
if (n <0  n >100){
cout << "out of range; ignored." << endl;
}
else {
++count;
sum += n;
range= maxmin
}
}
cout << "The average is " << float (sum)/count << endl;
cout << "The range is " << range << endl;
}