You want to use a pattern line the following (pseudocode, since questions like these are often homework and learning based, not find an answer and copy). I want great future programmers!
First the setup:
- Initialize a variable to the "What you should enter" message you plan for your user. Why? so if you need to change it, you only have one place to go!
- Initialize a variable to any error message(s) that you will detect
- Establish the input stream
Now the loop:
Issue the "what you should enter" message
Initialize any needed counters
begin the loop (while counters < value?)
// use try catch to surround your input and calculations to catch malformed integers etc
try {
get candidate data element from input stream
check for validity
if success increment count, do other needed work
if fail, reissue "what you should enter" message or more specific error message
} catch malformed input {
reissue "what you shoue enter" message, including error for malformed input
}
end loop
Note, if you are doing work until some condition occurs (e.g. the user enters QUIT), you use that condition (set to false the first time) as your loop termination test
z[i]>1if there is nothing in z[i]. You should get the input, test if it fits values, and then assign it to the array.