CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2011
    Posts
    1

    Cannot find Symbol Error

    Hi, first I would like to say that it is a pleasure to be part of this forum.
    Anyways I have an assignment due, and I am a perfectionist, so it is bugging me that it will not compile properly.

    Here is the assignment: You are planning to transport a large number of people on a trip. You have 45-passenger buses and 16-passenger vans at your disposal. Any bus you use must be completely filled, and any remaining passengers transported by van.

    You must write a Java program that returns the necessary numbers or each type of vehicle given the number of students to be transported. There should be methods to determine the number of buses, the number of vans and a main method to test them.

    Here is what I have done so far:

    public class bAndV{

    public static void main (String args[]) {
    System.out.println (bus(151));
    System.out.println (vans());
    }

    public static int bus(int bus){
    return bus/45;
    }

    public static int vans(int vans){
    int rem = bus % 45;
    if (rem % 45== 0)
    return (0);
    else
    return ((rem/16)+1);

    }

    }
    Error i recieve: cannot find symbol - variable bus
    What must I do for the second method to identify bus as a variable from the first method? Thank you for the help.

  2. #2
    Join Date
    Nov 2006
    Location
    Barcelona - Catalonia
    Posts
    364

    Re: Cannot find Symbol Error

    Hi,

    Please use code tags for code.
    You can save what bus() function returns into a variable to be passed to vans() function as an argument.
    Code:
    int busValue = bus(151);
    int vansValue = vans(busValue);
    You also have a mistake in vans() functions, where you are using an undeclared bus variable. I guess what you want is:
    Code:
    public static int vans(int vans){
       int rem = vans % 45;
       if (rem % 45== 0)
       return (0);
       else
       return ((rem/16)+1);
    }
    Regards,

    Albert.
    Please, correct me. I'm just learning.... and sorry for my english :-)

  3. #3
    Join Date
    Feb 2008
    Posts
    966

    Re: Cannot find Symbol Error

    To add a little to Albert's, it is generally considered bad practice to name your variables and methods the same. It can cause confusion when reading the code (yes, I know: methods have the parens, but still).

  4. #4
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    Re: Cannot find Symbol Error

    Code:
      int rem = vans % 45;
       if (rem % 45== 0)
    What is the point of using the remainder operator in the if statement. 'rem' already holds the remainder of the division of vans (which as ProgramThis has already stated is a poor name) by 45. Therefore it is going to be a number between 0 and 44 inclusive and so applying the remainder operator again is going to have no effect.
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

Tags for this Thread

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured