I need to find a way to keep a running tally of how many times events or actions occur. Say if a user is prompted to make inputs of 1 or 2, I want it to keep track of how many times 1 was entered, and how many times 2 was entered.
yes sir, i have it written until the end where i want it to display the results of how well the user did. now i need to go back through and take care of those possiable errors
Can you use ksh instead of sh? If so, you can easily test the answers with something like:
#!/bin/ksh
...possible code...
# Declare inputs as integers
integer n1=0 n2=0
...possible code...
# Take n1 input
until (( $n1 > 0 && $n1 < 21 )); do
print -n "Please enter a positive integer between 1 and 20: "; read n1
if (( $n1 < 0 || $n1 > 20 )); then
print "$n1 is out of range."
fi
done
# Take n2 input
until (( $n2 > 0 && $n2 < 21 )); do
print -n "Please enter another positive integer between 1 and 20: "; read n2
if (( $n2 < 0 || $n2 > 20 )); then
print "$n2 is out of range."
fi
done
If you want to display results and quit when the user hits Ctrl-C, you'll need to trap that signal. The syntax is