Are you maybe trying to do something like this?
That seems maybe backwards from what it appears that you are trying to do. Could you maybe help us out and explain what you are trying to do?
EDIT: Or are you saying that you want to see if it is a yes or no answer first, and if it isn't, then skip the code altogether?
[ December 13, 2005: Message edited by: C Clites ]
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..
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...