Search:

Type: Posts; User: helloworld922

Search: Search took 0.13 seconds.

  1. Replies
    25
    Views
    4,096

    Re: Need help creating this program

    Yep, that's right. There's only one bit of syntax error. You forgot to declare and initialize points to 0.

    In terms of performance, my solution is better ( O(1) vs. O(n) ) :P
  2. Replies
    25
    Views
    4,096

    Re: Need help creating this program

    it's because of variable scope. I don't know a good way to explain it, but basically you're declaring the int inside the if statement, so nothing outside of it can see it.

    The last problem I see...
  3. Replies
    25
    Views
    4,096

    Re: Need help creating this program

    if lectures <= 5
    points = 2 * lectures
    else
    points = 5 + lectures
  4. Replies
    25
    Views
    4,096

    Re: Need help creating this program

    an if/else statement only does one or the other... not both. Also, you want to add the 5 points if the lectures is greater than 5.

    Yes, you can do points = points+points, but it's not helpful here.
  5. Replies
    25
    Views
    4,096

    Re: Need help creating this program

    Mmm, there's a few problems but they can be easily fixed.

    You don't want to add 1 or 2 to the lecturesAttended to get the points, but rather multiply. You also have it backwards. It should be 2...
  6. Replies
    25
    Views
    4,096

    Re: Need help creating this program

    if/else statements are really simple. You ask is something true? If it is, you execute one set of code. If it's not, you execute the else code. It's almost exactly like the language equivalent: if...
  7. Replies
    25
    Views
    4,096

    Re: Need help creating this program

    :( what do you know how to do? From the way you phrased the question, it seems like you really do need some way to test conditionals, and if/else are the simplest.

    if/else is basically like it...
  8. Replies
    25
    Views
    4,096

    Re: Need help creating this program

    what is the algorithm for n lectures attended?

    first 5 give 2 points, all rest give 1?

    pseudo-code:

    count = lecturesAttended
    while count > 0
    if count > 5
    increase points by...
  9. Replies
    25
    Views
    4,096

    Re: Need help creating this program

    Write your algorithm out for if he attends n lectures. If it's always going to be 7 lectures, you might as well do this:


    System.out.println("For 7 lectures you get 12 points");

    Even if you're...
Results 1 to 9 of 9