new to Java as you can tell when you see my question. I want to:
- Prompt the user with the conversion menu
- If they select 5, for example, ask them for an input to convert to kilograms
- Keep giving them the menu until they enter 7 to quit
The problems with my code are - Whatever number is hit initially, step 2 from above doesn't appear. It only appears after the second number is entered -When 7 in entered it doesn't actually quit
I'm also new to this site so my apologies if I'm not asking the question properly
Here's the code
class Test
{
public static void main(String[] args)
{
int number;
int index;
int input;
Double conversion;
index = 1;
System.out.println("Enter 1 for Fahrenheit to Celius ");
System.out.println("Enter 2 for Celius to Fahrenheit ");
System.out.println("Enter 3 for Inches to Centimetres ");
System.out.println("Enter 4 for Centimetres to Inches ");
System.out.println("Enter 5 for Pounds to Kg ");
System.out.println("Enter 6 for Kg to Pounds ");
System.out.println("Enter 7 to quit ");
number = EasyIn.getInt();
for (index=1; index <=6; index++)
{
System.out.println("Enter 1 for Fahrenheit to Celsius ");
System.out.println("Enter 2 for Celsius to Fahrenheit ");
System.out.println("Enter 3 for Inches to Centimetres ");
System.out.println("Enter 4 for Centimetres to Inches ");
System.out.println("Enter 5 for Pounds to Kg ");
System.out.println("Enter 6 for Kg to Pounds ");
System.out.println("Enter 7 to quit ");
number = EasyIn.getInt();
if (number == 1)
{
System.out.print("Input an amount to convert to Celsius ");
input = EasyIn.getInt();
conversion = (5.0/9.0) * (input - 32);
System.out.println("Your input to Celsius is " + conversion);
System.out.println("Press 7 to quit");
}
if (number == 2)
{
System.out.print("Input an amount to convert to Fahrenheit ");
input = EasyIn.getInt();
conversion = input * 2.8;
System.out.println("Your input to Fahrenheit is " + conversion);
System.out.println("Press 7 to quit");
}
if (number == 3)
{
System.out.print("Input an amount to convert to Centimetres ");
input = EasyIn.getInt();
conversion = input * 2.54;
System.out.println("Your input to Centimtres is " + conversion);
System.out.println("Press 7 to quit");
}
if (number == 4)
{
System.out.print("Input an amount to convert to Inches ");
input = EasyIn.getInt();
conversion = input * 0.393701;
System.out.println("Your input to Inches is " + conversion);
System.out.println("Press 7 to quit");
}
if (number == 5)
{
System.out.print("Input an amount to convert to Kg ");
input = EasyIn.getInt();
conversion = input * 0.453592;
System.out.println("Your input to Kgs is " + conversion);
System.out.println("Press 7 to quit");
}
if (number == 6)
{
System.out.print("Input an amount to convert to Pounds ");
input = EasyIn.getInt();
conversion = input * 2.20462;
System.out.println("Your input to pounds is " + conversion);
System.out.println("Press 7 to quit");
}
}
}
}