I would like the user to be asked if they want to do multiplication, addition or subtraction again after they chose 'Y' at the end question, but it saves what option was initially chosen. Any suggestions ?
Thanks for all help,
Dave
class ass2{
public static void main (String[]args){
char menu;
char again;// char value declared
System.out.println("Welcome to Dave's Calculator");
System.out.println("Please chose from one of the following options");
System.out.println("[A] Addition");
System.out.println("[S] Subtraction");
System.out.println("[M] Multiplication");
menu = Keyboard.readChar();//allows menu value to be taken in from the users keyboard
menu = Character.toUpperCase(menu);
do{
while((menu != 'A')&&(menu != 'S')&&(menu != 'M')) {
System.out.println("Please chose options A , S or M");//error message if the user enters a value other than A, S or M
menu = Keyboard.readChar();//allows menu value to be taken in from users keyboard using keyboard.class
}
double number1, number2, result;
switch (menu){//switch for the menu to operate
case 'A' : System.out.println("You chose A for addition.");
System.out.println("Please enter number 1");
number1 = Keyboard.readDouble();
System.out.println("Please enter number 2");
number2 = Keyboard.readDouble();
result = number1 + number2;
System.out.println("The answer is: " + result);
break;
case 'S' : System.out.println("You chose S for subtraction.");
System.out.println("Please enter number 1");
number1 = Keyboard.readDouble();
System.out.println("Please enter number 2");
number2 = Keyboard.readDouble();
result = number1 - number2;
System.out.println("The answer is: " + result); break;
case 'M' : System.out.println("You chose M for multiplication.");
System.out.println("Please enter number 1");
number1 = Keyboard.readDouble();
System.out.println("Please enter number 2");
number2 = Keyboard.readDouble();
result = number1 * number2;
System.out.println("The answer is: " + result); break;
}
do{
System.out.println("would you like to calculate another sum?");
again=Keyboard.readChar();
again = Character.toUpperCase(again);//allows acceptance of capital y and n
}while(!(again =='N' || again =='Y'));
} while (again == 'Y');{
System.out.println("Welcome to Dave's Calculator");
System.out.println("Please chose from one of the following options");
System.out.println("[A] Addition");
System.out.println("[S] Subtraction");
System.out.println("[M]. Multiplication");
menu = Keyboard.readChar();//allows menu value to be taken in from the users keyboard
}
}
}

New Topic/Question
Reply



MultiQuote






|