Name: Anonymous 2013-04-17 22:18
Im trying to get this program to calculate rainfall but I screwed up the loop and Im not sure how to get it too work.
import java.util.Scanner;
public class RainDemo {
public static void main(String[]args)
{
Scanner keyboard = new Scanner(System.in);
double years;
double use=1;
double rainfall;
double raintotal=0;
double months;
double RA; //RA Rain average
double YT; //YT is year total
double YC; //YC is short for year counter
System.out.println("User 4/17/2013\n");
System.out.print("Enter the number of years: ");
years=keyboard.nextDouble();
if (years<=0)
{
System.out.print("Invalid. Enter 1 or greater: ");
years=keyboard.nextDouble();
}
raintotal=1;
months=1;
YC=1;
YT=years*12;
System.out.println("Enter the rainfall, in inches, for each month.");
//System.out.print(""); Backup line
for(YC=0;YC==years;YC++)
for(months=1;months>=12;months++)
{
System.out.print("Year "+YC +" month " +months);
rainfall=keyboard.nextDouble();
if (raintotal>=0)
{
System.out.print("Invalid. Enter 1 or greater: ");
rainfall=keyboard.nextDouble();
}
raintotal=raintotal+rainfall;
}
System.out.println("Number of months: "+YT);
RA=raintotal/YT;
System.out.println("Total Rainfall: "+raintotal+" Inches.");
System.out.println("Average monthly rainfall: "+RA+" Inches");
}
}
import java.util.Scanner;
public class RainDemo {
public static void main(String[]args)
{
Scanner keyboard = new Scanner(System.in);
double years;
double use=1;
double rainfall;
double raintotal=0;
double months;
double RA; //RA Rain average
double YT; //YT is year total
double YC; //YC is short for year counter
System.out.println("User 4/17/2013\n");
System.out.print("Enter the number of years: ");
years=keyboard.nextDouble();
if (years<=0)
{
System.out.print("Invalid. Enter 1 or greater: ");
years=keyboard.nextDouble();
}
raintotal=1;
months=1;
YC=1;
YT=years*12;
System.out.println("Enter the rainfall, in inches, for each month.");
//System.out.print(""); Backup line
for(YC=0;YC==years;YC++)
for(months=1;months>=12;months++)
{
System.out.print("Year "+YC +" month " +months);
rainfall=keyboard.nextDouble();
if (raintotal>=0)
{
System.out.print("Invalid. Enter 1 or greater: ");
rainfall=keyboard.nextDouble();
}
raintotal=raintotal+rainfall;
}
System.out.println("Number of months: "+YT);
RA=raintotal/YT;
System.out.println("Total Rainfall: "+raintotal+" Inches.");
System.out.println("Average monthly rainfall: "+RA+" Inches");
}
}