# Thread: Need help with homework

1. Member
Join Date
Feb 2011
Posts
18
Rep Power
0

## Need help with homework

Hi guys,

Im having some trouble figuring out how to write this program
Last edited by bkim33; 02-11-2011 at 06:35 AM. Reason: mistake

2. The first problem is that you set value and prevalue to v. Does that sound right to you? I would have thought you set prevalue to the last value the user entered not the current one. And you would only do that for a given situation such as IF the current value is greater than the previous value. Also, you might find this simpler if you use a boolean in the while loop instead.

3. Member
Join Date
Feb 2011
Posts
18
Rep Power
0
So how would I set prevalue to the last value while being able to enter in a new value ? sorry if im asking a dumb question im new to java and like I said, Im having a hard time learning this because I have to rely solely on the book.

4. Well everything depends upon what the current value the user enters. So how about after you get the value and store it into v* why not do a few tests to see if it is a valid input and what happens next is determined by those tests. I gave you a capital hint in my previous reply.

*you can actually do away with the v variable but lets not worry about that right now.

5. Member
Join Date
Feb 2011
Posts
18
Rep Power
0
I think i get where you are going so I got this so far but im still having the same issue

I know this is such a simple problem but my brain is so fried right now from an exam I have tomorrow as well
Last edited by bkim33; 02-11-2011 at 06:36 AM.

6. You have four conditions and you have only handled one.

1. If value is outside acceptible range
2. If input is not an integer. Check with teacher if you need to handle this one.
3. If current value is less than previous value
4. Happy days - valid input so we can do stuff.

Also, examine your if statement carefully. What happens if user enters -1?

7. Member
Join Date
Feb 2011
Posts
18
Rep Power
0
ok I made a lot of progress!! thanks a lot sir!

I stil have the issue of the initial value of 50 if i enter something larger than 50 I will have issues..
Last edited by bkim33; 02-11-2011 at 06:36 AM.

8. Now you have handled 2 of the possible 4 situations. Keep going.

9. Member
Join Date
Feb 2011
Posts
18
Rep Power
0
I made a variable of count initialized to 0 above the while loop; under else part of the loop i put count ++; after the while loop i print out the variable sum but the loop runs twice and stops why is this happening?

10. My magic 8-ball says: "Cannot predict now"

Do you think posting your lastest code might help?

#### Posting Permissions

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