Hi this is the question i was given
Write a menu driven program that allows the user to enter a value for x and provides three options:
i. Find the square of the number
ii. Find the cube of the number
iii. The third option allows the user to quit.
Make use of methods in your program for each option above. Note the methods to find the square and cube of the number should receive one parameter of type double and return the answer.
And here is my attemt. It compiles but it always cubes the number entered even if i choose option a to square. I've also tweaked the code to valadiate that the correct letters have been entered.
If you could highlight where im going wrong in red please.Any help would be greately appricated.
class WS1Q3 { public static void main(String[] args) { double x, result; char ans; System.out.println("enter a number"); x=Keyboard.readDouble(); System.out.println("press 'A' to square the number, 'B' to cube or 'C' to quit"); ans=Keyboard.readChar(); if(ans!='A' && ans !='B' && ans!='C' && ans!='a' && ans !='b' && ans!='c') { do // valadating correct letters entered { System.out.print("Error enter either A,B or C"); ans=Keyboard.readChar(); }while(ans!='A' && ans!='B' && ans!='C' && ans!='a' && ans !='b' && ans!='c'); } // use of if statment to use requested method if(ans == 'A' || ans == 'a') { result=square(x); } if(ans =='B' || ans =='b'); { result=cube(x); } if(ans == 'C' || ans =='c') { System.out.println("Goodbye"); } System.out.println("the result is "+result); System.out.println("Goodbye"); }//close main static double square(double x) { double result; result = x*x; return result; }//close method square static double cube(double x) { double result; result= x*x*x*x; return result; }//close method cube }//close class