I am supposed to write a program that calculates the total floor space in a house. The program prompts the user to enter the length & width of at least one room and it needs to verify with the user if he wants to enter more room dimensions.
It isn’t working. Someone please help me?
import java.util.*;
public class FloorSpace
{
public static void main (String[] args)
{
Scanner input = new Scanner(System.in);
double length = 0.0, width = 0.0, floorSpace = 0.0;
char ans;
do
{
System.out.print("Enter length: ");
length = input.nextDouble();
System.out.print("Enter width: ");
width = input.nextDouble();
floorSpace = length * width;
floorSpace += floorSpace;
System.out.print("Do you want to enter more room dimensions? (y/n): ");
ans = input.nextLine().charAt(0);
}
while (ans == 'y');
System.out.println("\nTotal floor space is " + floorSpace);
}
}
Oh my I just found out something’s wrong with my computation formula. Can someone please help me.
You are setting
floorSpacetolength * widthevery time and then incrementing that value by itself (which is really just multiplying it by two).Replace
with just