1
我正在創建一個將十六進制數轉換爲十進制數的程序。下面是代碼:十六進制到十進制Pascal錯誤使用Dev-Pascal非法表達式
program hexadesimal;
uses crt;
var
d, j, l, pow, y:integer;
x:longint;
h:string;
label z;
begin
z:
readln(h);
d:=0;
l:=length(h);
for j:=1 to length(h) do
begin
if (h[j] = 'A') then h[j] = '10';
if (h[j] = 'B') then h[j] = '11';
if (h[j] = 'C') then h[j] = '12';
if (h[j] = 'D') then h[j] = '13';
if (h[j] = 'E') then h[j] = '14';
if (h[j] = 'F') then h[j] = '15';
l:=l - 1;
pow := power(16, l);
val(h[j], x, y);
d := d + (x * pow);
end;
writeln(d);
readln;
end.
然而,當我編譯錯誤出現非法的表達和它指向這些行:
if (h[j] = 'A') then h[j] = '10';
if (h[j] = 'B') then h[j] = '11';
if (h[j] = 'C') then h[j] = '12';
if (h[j] = 'D') then h[j] = '13';
if (h[j] = 'E') then h[j] = '14';
if (h[j] = 'F') then h[j] = '15';
我該怎麼辦?
你能顯示完整的錯誤? –
錯誤:非法表達式(6行),有6個錯誤編譯模塊,停止@ManojSalvi –