# Storing count within a while

Graham Robinson
Greenhorn
Posts: 16
//variable
int rain, heaviest = 0, entry;
boolean valid;
float sum, average;

//for control
for(int count = 0; count < 12; count++)
{
do
{
c.out.println("Please input value of rainfull betweem 0 and 200mm.");
valid = (rain >= 0 && rain <= 200);
if (!valid)
c.out.println("The value entered isn't valid.");
}while (!valid);

if (rain > heaviest)
heaviest = rain;
{

This should take 12 values from the user, but how would i create the sum of all entries, as I'm not storing them? Say if the user enters 5 and 6, i need the it to count the total, so i can work out the average. I've managed to get it to print the heaviest value, but im stuck with the average.

thanks

Graham Robinson
Greenhorn
Posts: 16
It's ok, I've solved it now. Just incase anyone want's to know how i did it...

i used a float called total = 0.0f
then in the while i used, total = rain + total;
and an int entry,
as entry++

total / entry = average

thanks.

Joanne Neal
Rancher
Posts: 3742
16
On a stylistic point is usually written as

Graham Robinson
Greenhorn
Posts: 16
ahh, thanks for the tip.