Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: problem finding symbol

  1. #1
    Member
    Join Date
    Aug 2013
    Posts
    101
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cool problem finding symbol

    So, I was writing some code to figure out what's wrong with the code. I want to assign each mealcode a price.

    Here is my code:

     
    if ((request.contains("no beef") || request.contains("chicken")) && !(request.contains("child")))
        mealcode = 1;
        while (mealcode == 1)
            cost = 1.75;
    else if (request.contains("beef") && !(request.contains("child")))
        mealcode = 2;
        while (mealcode == 2)
            cost = 2.08;
    else if (request.contains("vegetarian"))
        mealcode = 3;
        while (mealcode == 3)
        cost = 2.14;
    else if ((request.conatins("child") && !(request.contains("vegetarian"))))
        mealcode = 4;
        while (mealcode == 4)
        cost = 0.98;
    else
        mealcode = 0;

    I get quite a few errors, including "cannot find symbol" and things that are a little more vague like "else without if" even though I gave each else an if as far as I could tell.

    All help appreciated, ghostheadx


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: problem finding symbol

    I suggest putting this into an SSCCE so we can compile it ourselves. This snippet leaves out a lot of valuable information that we need to answer the question. Also, list the errors you're getting- take them one at a time.

    Also also, always use curly braces and proper indentation with your if statements and loops.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: problem finding symbol

    mealcode = 1;
        while (mealcode == 1)
            cost = 1.75;
    Think very carefully about what this code is doing.
    Improving the world one idiot at a time!

  4. #4
    Member
    Join Date
    Aug 2013
    Posts
    101
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: problem finding symbol

    Alright, I guess that's just an infinite loop. Here's my new code:

     
    meals[1] += meals[0]/2;
    meals[2] += meals[0]/2;
    meals[1] += meals[0]%2;

    I'm trying to split a[0] equally between "Chicken-based adult" and "Beef-based adult."
    And if it's not an even number then I want to make "Chicken-based adult" be one more than "Beef based adult."

  5. #5
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: problem finding symbol

    Do you mean split each element of the array a[] as you've described, not just a[0]? If so you could do something like the elementary approach I've outlined below. There are more clever ways to accomplish the same thing, but this explains the logic most simply:

    1. determine if a[i] is even
    1.a if even, split the value evenly between chicken and beef
    1.b if not even, subtract one and split the result evenly between chicken and beef, then increase chicken by 1.

Similar Threads

  1. Replies: 1
    Last Post: June 23rd, 2013, 02:37 AM
  2. Problem with finding value from array
    By Alexryu in forum What's Wrong With My Code?
    Replies: 2
    Last Post: June 10th, 2013, 02:15 AM
  3. Problem finding MIN value of 2D arry.
    By rayan2004 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 22nd, 2012, 07:38 AM
  4. Problem: cannot find symbol
    By ganti91 in forum What's Wrong With My Code?
    Replies: 20
    Last Post: May 28th, 2012, 11:13 AM
  5. Problem Finding Value from List
    By WhiteSoup12 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 11th, 2012, 06:24 PM

Tags for this Thread