Two Problems Try catch and If
posted 13 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Hey, I have 2 problems if anyone can offer help i'd really appreciate it!
First problem I have is with my try and catch. Its hard to explain (I don't know whats wrong with it)
My second problem is with the bottom section where I ask do you want to check ten more? I want to return to the question when the else is triggered. I don't even know if this is possible.
Thanks for looking!
First problem I have is with my try and catch. Its hard to explain (I don't know whats wrong with it)
My second problem is with the bottom section where I ask do you want to check ten more? I want to return to the question when the else is triggered. I don't even know if this is possible.
Thanks for looking!
posted 13 years ago
What makes you think there is anything wrong with it ? Is it doing something when you think it shouldn't ? Is it not doing something that you think it should ?
-
1 -
-
Number of slices to send:Optional 'thank-you' note:
-
-
Karl Collins wrote:First problem I have is with my try and catch. Its hard to explain (I don't know whats wrong with it)
What makes you think there is anything wrong with it ? Is it doing something when you think it shouldn't ? Is it not doing something that you think it should ?
Joanne
Karl Collins
Greenhorn
Posts: 21
posted 13 years ago
Thanks for the reply,
Well when the try & catch triggers it seems to keep repeating the catch. Over and Over.
For example the program says
"2. Enter your age:"
And you type "apple"
the program says "ONLY AGES 4 - 5 AND 6" over and over.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Joanne Neal wrote:
Karl Collins wrote:First problem I have is with my try and catch. Its hard to explain (I don't know whats wrong with it)
What makes you think there is anything wrong with it ? Is it doing something when you think it shouldn't ? Is it not doing something that you think it should ?
Thanks for the reply,
Well when the try & catch triggers it seems to keep repeating the catch. Over and Over.
For example the program says
"2. Enter your age:"
And you type "apple"
the program says "ONLY AGES 4 - 5 AND 6" over and over.
posted 13 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
That's because the try-catch is inside the while loop, so after the code in the catch block is done, it's just going through the loop again.
Another problem is that the condition of the while loop is count <= 10 but you are not incrementing count anywhere (you're only decrementing it in a couple of places) so it's going to take very long for count to become 10.
Another problem is that the condition of the while loop is count <= 10 but you are not incrementing count anywhere (you're only decrementing it in a couple of places) so it's going to take very long for count to become 10.
posted 13 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
You may also try, inside the catch Exception block, to call userin.next();
That would help clearing out the invalid input you previously inserted.
Claudiu
That would help clearing out the invalid input you previously inserted.
Claudiu
posted 13 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
this is some very confusing code for me.. i will keep trying to figure it out
i am certain it is but i am still trying to figure out your code.
i give up i cant tell what you are trying to do
I don't even know if this is possible.
i am certain it is but i am still trying to figure out your code.
i give up i cant tell what you are trying to do
SCJP
Visit my download page
Karl Collins
Greenhorn
Posts: 21
posted 13 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Ok I am sorry for the shitty explanation. First off I tried to put the catch outside of the loop but it doesn't work.
What I want is to ask "What age are you" ten times. I want only 4, 5 and 6 to be able to be entered and anything else to be refused. All other numbers entered will be handled by my else statement but whenever a character is entered the program receives an error and quits. So I used the Try/Catch. But for some reason when the catch is triggered it loops over and over again. I only want the try/catch to do the same thing my else does.
Ill worry about the second bit when I fix this first bit.
I hope you can understand now.
Thanks or the replys
Oh and I don't fully understand what Claudia was saying although maybe she is right? Sorry for the ignorance.
What I want is to ask "What age are you" ten times. I want only 4, 5 and 6 to be able to be entered and anything else to be refused. All other numbers entered will be handled by my else statement but whenever a character is entered the program receives an error and quits. So I used the Try/Catch. But for some reason when the catch is triggered it loops over and over again. I only want the try/catch to do the same thing my else does.
Ill worry about the second bit when I fix this first bit.
I hope you can understand now.
Thanks or the replys
Oh and I don't fully understand what Claudia was saying although maybe she is right? Sorry for the ignorance.
Karl Collins
Greenhorn
Posts: 21
posted 13 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Edit: I solved most of this problem thanks for the help for now ranchers!!
| How do they get the deer to cross at the signs? Or to read this tiny ad? Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing |











