# Need help with homework

• 02-11-2011, 02:21 AM
bkim33
Need help with homework
Hi guys,

Im having some trouble figuring out how to write this program
• 02-11-2011, 02:30 AM
Junky
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.
• 02-11-2011, 02:43 AM
bkim33
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.
• 02-11-2011, 02:47 AM
Junky
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.
• 02-11-2011, 02:57 AM
bkim33
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
• 02-11-2011, 03:14 AM
Junky
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?
• 02-11-2011, 03:15 AM
bkim33
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..
• 02-11-2011, 03:18 AM
Junky
Now you have handled 2 of the possible 4 situations. Keep going.
• 02-11-2011, 05:38 AM
bkim33
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?
• 02-11-2011, 05:50 AM
Junky
My magic 8-ball says: "Cannot predict now"

Do you think posting your lastest code might help?