Keep getting result of 0.
I know I had to set the variables "occupied" and "total" to 0 to avoid getting an error, but whenever I run it, I get the "rate" keep equaling to 0. I need the rate to be the number of occupied rooms divided by the number of total rooms.
Code:
import java.util.Scanner; //gets the Scanner
public class LBHotelOccupancy
{ //begin class
public static void main(String[] args)
{ //begin main method
int floor, floors; //The floor number and the total number of floors, respectively.
Scanner input = new Scanner(System.in);
//Politeness and and intro to the program
System.out.println("Hello! I can calculate the occupancy rate for each floor in your hotel.");
System.out.println("Please answer the following questions.");
//Get the number of floors
System.out.print("How many floors are in your hotel? ");
floors = input.nextInt();
for(floor = 1; floor <= floors; floor++) //will increment the floor number with each loop until the total floors is reached
{
System.out.print("How many rooms are on floor " + floor + "? ");
int total = input.nextInt(); //get total rooms on floor
System.out.print("How many rooms on floor " + floor + " are occupied? ");
int occupied = input.nextInt(); //get occupied rooms on floor
System.out.println();
double rate = occupied / total; //calculation for occupancy rate
System.out.println("The occupancy rate for floor " + floor + " is " + rate + "."); //display occupancy rate
System.out.println();
}
} //end main method
} //end class