Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Do whiles/Fors and Drawing

 
Graham Robinson
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, this code is to take 12 inputs from the user, then print the largest and average value, then print a bar chart using the drawing window to produce bars. But at the moment, i can't even get this do while etc to work, it just doesn't add the count, or maybe i have it in the wrong place, it allows me to enter as many values as i like. Any help would be great thanks,

import element.*;
import java.awt.Color;

/**
* Prompt user for 12 values of rainful
* and produce the heaviest, average value and bar chart.
* @Author Graham Robinson
* @version 1 November 2005
*/

public class AuchenWeather
{

public static void main (String[] args)
{

//consrtuct new console window
ConsoleWindow c = new ConsoleWindow();

// construct a drawing window object
DrawingWindow d = new DrawingWindow();

//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.");
rain = c.input.readInt();
valid = (rain >= 0 && rain <= 200);
if (!valid)
c.out.println("The value entered isn't valid.");
}while (valid);

if (rain > heaviest)
{
heaviest = rain;
sum = 0;
average = sum / 12;
c.out.println("Heaviest rainfull = " + rain);

}//end if


}//end of for



}//end of class
}//end of main
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your condition should be
 
Graham Robinson
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, worked a treat
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic