program Project1;
uses
math;
var
num1: integer;
power: integer;
answer: integer;
begin
writeln('This program will accept two input values and raise the first number to the power of the second value');
writeln('Please enter the first number');
readln(num1);
writeln('Please enter the second number');
readln(power);
answer:= (num1**power);
writeln(answer);
readln();
end.
我一直在不懈地研究小时,以查找如何将变量num1限制在1到10之间
答案 0 :(得分:1)
要验证输入,一种可能性是创建一个为您验证输入的函数。 传递值和最小,最大范围,并根据测试结果设置功能值。
function ValidInteger( value : Integer; min,max : Integer) : Boolean;
begin
Result := (value >= min) and (value <= max); // Or ValidInteger := etc
end;
在您的代码中,如下所示:
min := 1;
max := 10;
repeat
writeln('Please enter the first number [',min,'..',max,']:');
readln(num1);
until ValidInteger(num1,min,max);