M
Markus Pitha
Hello,
What's the best way, to solve the difficulty of too big entries and
resulting wrong calculations of the program.
I want to give an example:
Imagine I have a calculation program and the first variable is int
(-32768 to 32767). So when I allow the user to enter values up to 32767
and the user adds then 10 to this value, it is out of range.
Or what should I do, when the user takes the square of 30000, it's then
out of range too.
What's the best method to solve such problems. Would it make sense to
choose the variables as big as possible, and restrict the user's input
to a number wide under this range?
I also thought about reading just a specific count of digits with fgets
from stdin, but when I enter some more digits, fgets saves the remaining
digits and writes it into the keyboard buffer.
What can I do?
Markus.
What's the best way, to solve the difficulty of too big entries and
resulting wrong calculations of the program.
I want to give an example:
Imagine I have a calculation program and the first variable is int
(-32768 to 32767). So when I allow the user to enter values up to 32767
and the user adds then 10 to this value, it is out of range.
Or what should I do, when the user takes the square of 30000, it's then
out of range too.
What's the best method to solve such problems. Would it make sense to
choose the variables as big as possible, and restrict the user's input
to a number wide under this range?
I also thought about reading just a specific count of digits with fgets
from stdin, but when I enter some more digits, fgets saves the remaining
digits and writes it into the keyboard buffer.
What can I do?
Markus.