#Not quitting

1 messages ยท Page 1 of 1 (latest)

karmic cave
#

I have made this menu it all works fine apart from clicking 0 and qutiting it just shows the menu and the options when I want it to quit when clicking 0 but really cant see what im doing wrong.

sonic pecanBOT
#

<@&987246399047479336> please have a look, thanks.

sonic pecanBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

#

Here is an AI assisted attempt to answer your question ๐Ÿค–. Maybe it helps! In any case, a human is on the way ๐Ÿ‘. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.

#

To help you troubleshoot the issue, please provide the code you have written so far.

karmic cave
#
/**
 * Programming with methods
 */
public class MyProgram
{
    public void runMyProgram()
    { 
        Scanner input = new Scanner(System.in);
        
        int choice = 0;
        
        
        
        
        
        
        while(choice != 3){
            System.out.println("0. Quit ");
            System.out.println("1. Area of a cricle ");
            System.out.println("2. Area of a rectangle ");
            
            System.out.println("Pick a number");
            
            
            choice = input.nextInt();
            
            
            
            
            
            
            double radius = 0;
            
            double length = 0;
            double width = 0;
            
            switch(choice){
                
                
            case 1:
                System.out.println("Pick a radius for the circle");
                
                radius = input.nextDouble();
                
                double area1 = circleArea(radius);
                System.out.println("The area of the circle is " + area1);
                break;
                
            case 2:
                System.out.println("Pick a length");
                
                
                length = input.nextDouble();
                System.out.println("Pick a width");
                width = input.nextDouble();
                double area2 = rectangleArea(length, width);
                System.out.println("The area of the rectangle = " + area2);
                break;```
sonic pecanBOT
# karmic cave ```import java.util.Scanner; /** * Programming with methods */ public class My...

Detected code, here are some useful tools:

Formatted code
import java.util.Scanner;

/**
 * Programming with methods
 */
public class MyProgram {
  public void runMyProgram() {
    Scanner input = new Scanner(System.in);
    int choice = 0;
    while (choice != 3) {
      System.out.println("0. Quit ");
      System.out.println("1. Area of a cricle ");
      System.out.println("2. Area of a rectangle ");
      System.out.println("Pick a number");
      choice = input.nextInt();
      double radius = 0;
      double length = 0;
      double width = 0;
      switch (choice) {
        case 1 : System.out.println("Pick a radius for the circle");
        radius = input.nextDouble();
        double area1 = circleArea(radius);
        System.out.println("The area of the circle is " + area1);
        break ;
        case 2 : System.out.println("Pick a length");
        length = input.nextDouble();
        System.out.println("Pick a width");
        width = input.nextDouble();
        double area2 = rectangleArea(length, width);
        System.out.println("The area of the rectangle = " + area2);
        break ;
karmic cave
#
                
                    
            case 0:
                System.out.println("Quitting Program");
                break;                
                
            default:
                System.out.println("Not valid please try again");
                    
                
                
                
            }
        }
        
    
        // invoke whatever subordinate methods you have defined
    }
    
    //Define as many subordinate methods as you like
    
    //Method for circleArea
    public static double circleArea(double radius){
        return Math.PI * radius * radius;
    }
    
    //Method for rectanlgleArea
    public static double rectangleArea(double length, double width)
    {
        return length * width;
        
        
    }
    
    public static void main(String[] args)
    { 
        MyProgram prog = new MyProgram();  //create an object
        prog.runMyProgram();  //invoke the top method

    }
    
    
}```
sonic pecanBOT
# karmic cave ``` case 0: ...

Detected code, here are some useful tools:

Formatted code
case 0 : System.out.println("Quitting Program");
break ;
default  : System.out.println("Not valid please try again");
}
}
// invoke whatever subordinate methods you have defined
}
//Define as many subordinate methods as you like
//Method for circleArea
public static double circleArea(double radius) {
return Math.PI * radius * radius;
}
//Method for rectanlgleArea
public static double rectangleArea(double length, double width) {
return length * width;
}
public static void main(String[] args) {
MyProgram prog = new MyProgram();
//create an object
prog.runMyProgram();
//invoke the top method
}
}
karmic cave
#

So is there no way to make it 0?

#

Thank you it works

#

But the option has be 0 when quitting

#

Or do I just have to deal with it lol

#

Cause its been annoying me

#

becausee I put choice != 3 so it will run as long as the vlue is not equal to 3

#

But when I do it as 0 it didnt work

#

I changed int choice = -1; to this from int choice = 0; and I made this while(choice != 0) from while(choice != 3)

#

So now we are pretty much there accpet it says not valid when its only meant to say that when you dont pick one of the options

#

Everything works fine but why is it printing not valid rather than quitting programme?

#

Ok I found out its because I needed to change case 3; to case 0; ๐Ÿ˜‚

#

Always a mistake somewhere thank you

sonic pecanBOT
#

Closed the thread due to inactivity.

If your question was not resolved yet, feel free to just post a message to reopen it, or create a new thread. But try to improve the quality of your question to make it easier to help you ๐Ÿ‘

sonic pecanBOT
#

Your question has been closed due to inactivity.

If it was not resolved yet, feel free to just post a message below
to reopen it, or create a new thread.

Note that usually the reason for nobody calling back is that your
question may have been not well asked and hence no one felt confident
enough answering.

When you reopen the thread, try to use your time to improve the quality
of the question by elaborating, providing details, context, all relevant code
snippets, any errors you are getting, concrete examples and perhaps also some
screenshots. Share your attempt, explain the expected results and compare
them to the current results.

Also try to make the information easily accessible by sharing code
or assignment descriptions directly on Discord, not behind a link or
PDF-file; provide some guidance for long code snippets and ensure
the code is well formatted and has syntax highlighting. Kindly read through
https://stackoverflow.com/help/how-to-ask for more.

With enough info, someone knows the answer for sure ๐Ÿ‘