
Double returns 1.#INF
I understand 1.#INF represents infinity and I am sure the issue is simple, but I cannot for the life of me figure out what is causing it. The issue is when trying to find the average. Everything seems like it is in its place.
Code:
/*
CMPSC 101
Section 01
Fall Semester
2010
Justin Eckrote
JAE5086
*/
#include <iostream>
#include <string>
using namespace std;
int main () // Program determines what fruit you want.
{
double number, tot, counter, average, range, low, high;
counter = 0.0;
tot = 0.0;
low = 100.0;
high = 0.0;
while (!cin.eof())
{
cin >> number;
if ((number >= 0.0) && (number <= 100.0))
{
if (number < low)
{
low = number;
}
if (number > high)
{
high = number;
}
counter = counter + 1.0;
tot = tot + number;
}
if ((number < 0.0) && (number > 100.0))
{
cout << "out of range; ignored." << endl;
}
}
if (counter = 1.0)
{
cout << "No data was entered" << endl;
}
else
{
average = tot / counter;
cout << "The average is " << average << endl;
range = high  low;
cout << "The range is " << range << endl;
}
}

Examine your if statements for = where you should be using ==

Ok, I am pretty sure I ran into that problem before. Hopefully with a little more practice I will remember to use == instead of = inside if statements. Thanks for the help
One problem down, a new one up. Now that the calculation is not coming up with 1.#INF, I find that the calculation is incorrect. There appears to be no flaw in the math itself, as this is a pretty simple equation. Yet, the numbers are off.
Example: Input 1, 3, then break the loop with control+z. This returns an average of 3.5 instead of 2.

About forgetting '==' and '=' difference:
You can try using: Code:
if (25 == variable)
In other words, put rvalue first, and lvalue later. If you forget one '=' there, then you'll get a compiler error, because you just tried to assign to rvalue. ;)