cannot find symbol error...?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • JavaNewBe
    New Member
    • Nov 2009
    • 2

    cannot find symbol error...?

    i encountered this problem, yet as much as i tried, could not find the source to this error.
    Code:
    import java.util.*;
    import java.io.*;
    
    public class billing {
    
        public static void main(String args[]) 
        	{
        	Scanner kbReader = new Scanner (System.in);
        	System.out.println("How many jerseys? ");
        	int jersey = kbReader.nextInt();
        		
        		
        	System.out.println("How many trousers? ");
        	int trouser = kbReader.nextInt();
        		
        	if (jersey>=50)
        	{
        			
        	if (trouser>=50)
        {
        		if (jersey>=trouser)
        		{int leftoverJ = jersey - trouser;}
        		{double costj = leftoverJ*64.95;}
        		{double costUniform = trouser*79.95;}
        }	
        		else 
        		  {int leftoverT = trouser - jersey;}
        		   {double costT= leftoverT*42.5;}
        		   {double costUniform = jersey*79.95;}
        	}		
        			
        		
        else 
        System.out.println("Total cost: " + (64.95*jersey + 42.5*trouser));
        			 		
        } 
        
    }
    Last edited by Frinavale; Dec 2 '09, 09:40 PM. Reason: Please post code in [code] ... [/code] tags. Added code tags.
  • JavaNewBe
    New Member
    • Nov 2009
    • 2

    #2
    Here's the error message:

    ------------------Configuration: <Default>--------------------
    C:\Users\Hoang\ Documents\billi ng.java:30: cannot find symbol
    symbol : variable leftoverJ
    location: class billing
    {double costj = leftoverJ*64.95 ;}
    ^
    C:\Users\Hoang\ Documents\billi ng.java:35: cannot find symbol
    symbol : variable leftoverT
    location: class billing
    {double costT= leftoverT*42.5; }
    ^
    2 errors

    Comment

    • pbrockway2
      Recognized Expert New Member
      • Nov 2007
      • 151

      #3
      Try this:

      Code:
      if (jersey>=50)
      {
          if (trouser>=50)
          {
              if (jersey>=trouser)
              {
                  int leftoverJ = jersey - trouser;
                  double costj = leftoverJ*64.95;
                  double costUniform = trouser*79.95;
              }
              else
              {
                  int leftoverT = trouser - jersey;
                  double costT= leftoverT*42.5;
                  double costUniform = jersey*79.95;
              }
          }
      }
      else
          System.out.println("Total cost: " + (64.95*jersey + 42.5*trouser));
      }
      Use the braces to group together the statements that refer to a given condition (that is either the if part, or the else part). Do this even if there is only one such statement like the last else part in your code. But do not go wrapping everything in braces as this will end up being very confusing at best.
      Last edited by pbrockway2; Nov 25 '09, 03:54 AM. Reason: altered the code - which is a bit of guesswork

      Comment

      Working...