I'm a little confused about your question. Are you talking about creating a catch block to handle an exception? Or are you talking about checking values that the user enters with if statements like you have?
I'm not convinced that you want to catch anything, and I'm not sure how to explain to you that I don't think that is what you want to do. A try/catch statement is for catching program errors..
Definition: An exception is an event that occurs during the execution of a program that disrupts the normal flow of instructions during the execution of a program.
What I think you really want to do is something like as follows:
Some ways of handling bad input are ignoring the input (bad idea), or somehow letting the user know that their input was bad (better). I would consider that a normal event, and not one that disrupts the flow of a program.
Unless you are really interested in generating custom exceptions..
Thanks, i did do that initially, but the problem is when i put something bad in, it generates the game numbers again. Ill figure it out. Try this and see what i mean. The uses is only allowed 1 roll each turn.
Stephen Foy - Microsoft Application Development Consultant
I understand what you are trying to do, and after looking at your code a bit, I'm pretty sure you know what you need to do, although I think some restructuring is called for. I suggest maybe sitting down with your pencil and paper and thinking it through a bit... you have so many loops and whiles that it is hard to keep track of everything.
If I am following your descriptions, basically you have three rolls to get the highest score. On each of the three rolls, you have the option of saving one of the scores. After three rolls, the scores are added, and the score printed.
One place I would look at starting is
Keep the totals and amount of rolls outside of the loop.. that way they don't get reset each time.
but the problem is when i put something bad in, it generates the game numbers again. Ill figure it out. Try this and see what i mean.
What I would do in this case is that if the user puts in something bad (something other than y or n), then make it default to no (do not save the highest roll). That way, you only need to check if the user chose yes.. so you would have something like:
Or if you want, you can check if it is a y or n, and if it isn't, prompt the user for a valid input.
Another thing that may be nit-picky... you don't need an array to hold the highest values. Since the values are going to be totaled, why not just keep a single int to keep track of the running score? Then there is no need for a seperate loop to total the scores later. You only need to print out the total.
Also, you don't need an array to hold the rolls either, you just need a single int to hold the highest roll for that round. It is initially a little more tricky to code, but your code will be more simple, and easier to read.
I think the one thing that will help you the most is to use a pencil and paper and draw out your program. It should give you a much clearer idea of what you want to do...