Results 1 to 5 of 5
  1. #1
    name is offline Member
    Join Date
    Oct 2011
    Posts
    31
    Rep Power
    0

    Default Cannot resolve symbol error

    Hello,

    I am writing a simple calculator code, but when I compile it, I get an error message regarding one of the variables that doesn't make sense. I will attach a copy of the code and an image of the error message.

    Thanks in advance,

    name

    Here is the code...

    Java Code:
    import java.io.*;
    import java.util.*;
    import java.text.*;
    
    public class calculator{
        public static void main(String []args) throws IOException
        {
    
            //create input stream
            BufferedReader in;
            in = new BufferedReader(new InputStreamReader(System.in));
    
            //input numbers
            System.out.println(" ");
            System.out.println("First number:");
            String in_num1 = in.readLine();
    
            System.out.println(" ");
            System.out.println("Second number:");
            String in_num2 = in.readLine();
            System.out.println(" ");
    
            //convert to int
            double num1=Double.valueOf(in_num1).doubleValue();
            double num2=Double.valueOf(in_num2).doubleValue();
    
            //start loop
            String input;
            int choice;
            do 
            {
    
                //output options
                System.out.println("Operations guide");
                System.out.println("1 = Add");
                System.out.println("2 = Subtract");
                System.out.println("3 = Multiply");
                System.out.println("4 = Divide");
                System.out.println("5 = Exit Calculator");
                System.out.println(" ");
    
                //ask for operation
                System.out.println("input operation");
                String inputed_operation = in.readLine();
                System.out.println(" ");
    
                //convert to int
                int chosen_operation = Integer.valueOf(inputed_operation).intValue();
    
                switch (choice)
                {
                    //operations
                    case 1:
                        System.out.println(num1 + "+" + num2 + "=" + (num1 + num2));
                        break;
                    case 2:
                        System.out.println(num1 + "-" + num2 + "=" + (num1 - num2));
                        break;
                    case 3:
                        System.out.println(num1 + "*" + num2 + "=" + (num1 * num2));
                        break;
                    case 4:
                        System.out.println(num1 + "/" + num2 + "=" + (num1 / num2));
                        break;
                    default:
    	            System.err.println ("Unrecognized option");
    	            break;
                }
            }
            while(chosen_operation != 5);
        }
    }
    Attached Thumbnails Attached Thumbnails Cannot resolve symbol error-capture.png  

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,001
    Rep Power
    10

    Default Re: Cannot resolve symbol error

    You chosen_operation variable is declared inside your do-while loop. That means you can't access it outside the loop, including within the while statement.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    name is offline Member
    Join Date
    Oct 2011
    Posts
    31
    Rep Power
    0

    Default Re: Cannot resolve symbol error

    Thanks, but do you know how I could use the variable "chosen_operation" to select one of the four math operations?

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,001
    Rep Power
    10

    Default Re: Cannot resolve symbol error

    If you want the variable to be available outside the loop, then declare it outside the loop.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    name is offline Member
    Join Date
    Oct 2011
    Posts
    31
    Rep Power
    0

Similar Threads

  1. How can I fix "Cannot resolve symbol" error
    By yma16 in forum IntelliJ IDEA
    Replies: 4
    Last Post: 05-16-2011, 01:28 PM
  2. BufferedReader error cannot resolve symbol
    By SwEeTAcTioN in forum New To Java
    Replies: 12
    Last Post: 10-22-2009, 06:22 AM
  3. Yet another Cannot Resolve Symbol
    By Gabinka in forum New To Java
    Replies: 5
    Last Post: 03-27-2009, 11:28 PM
  4. Cannot Resolve Symbol error...
    By seral1969 in forum New To Java
    Replies: 4
    Last Post: 02-18-2008, 01:17 AM
  5. Error: cannot resolve symbol, help me
    By mathias in forum Enterprise JavaBeans (EJB)
    Replies: 1
    Last Post: 08-06-2007, 03:46 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •