Hi, from a book I'm reading, I made a volume calculator using a foreign subroutine. The subroutine (TextIO) can be found by
CLICKING HERE
The code for what I've made is as followed:
Code:
public class Volume {
public static void main(String[] argv) {
float squareLength;
float area;
float otherDimension;
float volume;
TextIO.put("Please enter the length of your square cuboid face: ");
squareLength = TextIO.getlnInt();
area = (float)Math.pow(squareLength,2);
System.out.print("Your area is: ");
System.out.println(area);
TextIO.put("Please enter the length of your other dimension: ");
otherDimension = TextIO.getlnInt();
volume = area * otherDimension;
System.out.print("The volume of this shape is: ");
System.out.println(volume);
}
}
Basically, by using TextIO, this system works out the volume by squaring squareLength and then multiplying the area by the other dimension. The system works fine, apart from one problem: whenever you square a decimal number or multiply a decimal number by the area in this system, it randomly rounds the number either down despite the fact I'm using primitive type
float.
I don't want it to change the number at all, I want the system to print the actual number for the area and the volume.
Thanks