I am trying to understand how loops work but I can't seem to piece it together. I am working on a shipping java program and whatever I try will not work. So far I have when the integers are correct it proceeds with the program, but I want it when I put in an invalid number (such as zero or a negative) to ask again.
Scanner input = new Scanner (System.in);
int weight;
int distance;
int rate;
System.out.println("Welcome to the You Send It We Rend It Shipping Company!"); {
System.out.println ("How heavy is your package in pounds?");
weight = input.nextInt();
}
while (weight <=1 || weight >=60);{
System.out.println ("How far will you be shipping the package in miles?");
distance = input.nextInt();
}
while (distance <1);
double x = 0.00;
if (weight >= 1) x=5.01;
if (weight >=11) x=7.02;
if (weight >=21) x=9.03;
if (weight >=31) x=11.04;
if (weight >=41) x=15.00;
rate = (distance+99)/100;
System.out.printf ("Your total shipping cost for %d miles is $%s\n",distance, rate*x);
}
Also, I would like to fully understand why the rate is that way...?
rate = (distance+99)/100;