c++ homework help

Hi, im learning about floating point values right now. I understand how they are used in averages and other numbers with a decimal. i also know they dictate between types like double and int. But my homework is asking to write a program that reads a set of floating point values. then ask the user to enter tha values and print:
-the average of the values
-the smallest of the values
-the largest of the values
-the range
I have the smallest and largest. I put what i thought the average and range should be. This is what i have so far


#include <iostream>
using namespace std;
int main()
{
double total = 0.0;
int count = 0.0;
double input;
while (cin >> input)
{
total = total + input;
count++;
}
double average = 0.0;
if (count > 0)
{
average = total / count;
}
double smallest;
cin >> smallest;
double input;
while (cin >> input)
{
if (input < smallest)
{
smallest = input;
}
}
double largest;
cin >> largest;
double input;
while (cin >> input)
{
if (input > largest)
{
largest = input;
}
}
double input;
double smallest;
cin >> smallest
double largest;
cin >> largest;
double range = 0.0
range = largest - smallest
while (largest > smallest)
{
cout << range, endl;
}
return;


I was hoping i could get some help with the average and range. I know what they are supposed to say, but im not sure how exctly to put it. Thanks in advance.
int count = 0.0; // I would use simply int count = 0;

In the 'while' loop where you insert the numbers and where you keep a counter, I would check whether the number entered is the largest or smallest.

1
2
3
4
5
6
7
8
9
10
11
12
13
double largest = 0;
double smallest = DBL_MAX;
while (cin >> input)
{
if(input > largest)
 largest = input;

if(input < smallest)
 smallest = input;

total = total + input;
count++;
}


range is everything between smallest and largest, right?
Topic archived. No new replies allowed.