Im writting a program that prompts the user for two integers. Then displays a me
ID: 3641496 • Letter: I
Question
Im writting a program that prompts the user for two integers. Then displays a menu asking them to pick: 1. Addition 2. Subtraction 3. Quit. If they enter a number not 1-3 it asks them to enter it again.I got all of that. My problem after that it is supposed to return to the menu until they select 3 to quit. I cannot get it to work. Can anyone help me? Here is what I have:
import java.util.Scanner;
public class CalcJava {
public static void main(String[] args) {
int num1,num2;
int choice=0;
char responseChar;
String response;
Scanner input = new Scanner(System.in);
// Ask the user for two integers.
System.out.println("Enter first integer: ");
num1=input.nextInt();
System.out.println("Enter second integer: ");
num2=input.nextInt();
do
{
while(choice<1 || choice >3)
{
System.out.println("Please pick a number from the menu: ");
System.out.println("1. Add numbers 2. Subtract numbers 3. Quit");
System.out.println("Enter your choice(1-3): ");
choice = input.nextInt();
if (choice >3)
System.out.println("You entered an invalid selection");
if(choice==3)
System.exit(1);
if(choice==1)
System.out.println("Result: "+(num1+num2));
else if(choice==2)
System.out.println("Result: "+(num1-num2));
}
System.out.println("Do you want to go again?");
response=input.nextLine();
responseChar = response.charAt(0);
{
while(responseChar=='y');
}
}
}