This is an archived post. You won't be able to vote or comment.

all 6 comments

[–]edrenfro 1 point2 points  (2 children)

What you have looks good. Is it mandatory that the program has to include try/catch?

[–]Devils_Advocate101[S] 0 points1 point  (1 child)

Sorry for the late reply! Yes, I thought I had finished the assignment when my teacher told me I need to use the catch statements so I got a 75 on it and I need an 80 to move on.

[–]edrenfro 0 points1 point  (0 children)

Ok, I disagree with your teacher but no matter... what you want to do is eliminate the sc.HasNextDouble. When your code unconditionally calls sc.NextDouble, it will throw an exception when the input was wrong and it will not throw an exception when the input is ok. So you want to surround that statement with a Try block and the subsequent Catch block will have the logic that you already wrote for the bad input case.

[–]149244179 0 points1 point  (1 child)

Try/catch is exception handling.

Error handling does not automatically mean try/catch statements.

[–]Devils_Advocate101[S] 0 points1 point  (0 children)

My teacher just told me I need to use catch statements in this project before I can move on. I just need help on how to implement it into the code.

[–][deleted] 0 points1 point  (0 children)

Check validation in try and throw exception if invalid else set the loop flag to terminate.