Recent

Author Topic: Program unexpected pause  (Read 292 times)

FPnewbie

  • New member
  • *
  • Posts: 6
Program unexpected pause
« on: March 24, 2021, 01:59:38 am »
I have a simple command line program in which I enter 10 variables using writeln prompts and readln instructions to enter the data. The program pauses after the last readln and will not continue unless I hit the enter key 10 times. The program compiles and runs perfectly except for this annoying occurance.  This was a turbo pascal program and it worked perfectly using writeln and readln. What is there about these commands that i am not understanding?

Handoko

  • Hero Member
  • *****
  • Posts: 4205
  • My goal: build my own game engine using Lazarus
Re: Program unexpected pause
« Reply #1 on: March 24, 2021, 02:08:57 am »
Please provide us the source code.

FPnewbie

  • New member
  • *
  • Posts: 6
Re: Program unexpected pause
« Reply #2 on: March 24, 2021, 02:27:54 am »
File attached. The program stops at line 121 which is the last readln instruction. You can keep hitting the enter key and it will eventually run and finish.

Handoko

  • Hero Member
  • *****
  • Posts: 4205
  • My goal: build my own game engine using Lazarus
Re: Program unexpected pause
« Reply #3 on: March 24, 2021, 03:10:29 am »
You have an extra ReadLn in line #47. Disable or remove it.

This is your orginal source code:

Code: Pascal  [Select][+][-]
  1. program convert;
  2.  
  3. uses crt,
  4.     math;
  5.  
  6.  var  a:real;
  7.       b:real;
  8.       az: real;
  9.       ddmmss: real;
  10.       dd: real;
  11.       mm: real;
  12.       ss: real;
  13.       decdeg: real;
  14.       dsec: real;
  15.       dmin: real;
  16.       sec: real;
  17.       option: string ;
  18.       sdia: real;
  19.       ghaoh: real;
  20.       gha24h: real;
  21.       decloh: real;
  22.       decl24h: real;
  23.       lat: real;
  24.       long: real;
  25.       ut1: real;
  26.       crm: real;
  27.       crs: real;
  28.       gha: real;
  29.       lha: real;
  30.       decl: real;
  31.       angle: real;
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38. procedure dms_to_dec (ddmmss: real);
  39.       begin
  40.       dd:=int(ddmmss);
  41.       {writeln('degrees = ', dd:3:2);}
  42.       mm:= (frac (ddmmss))*100;
  43.       mm:= int(mm);
  44.       {writeln ('minutes= ',mm:3:2); }
  45.       sec:= (frac(ddmmss*100))*100;
  46.       {writeln ('seconds = ',sec:2:2);}
  47.       readln;
  48.       dsec:=(sec/60)+mm;
  49.       dmin:= dsec/60;
  50.       decdeg:= dd+(dmin);
  51.      {writeln ('decimel deg = ',decdeg:8:6); }
  52.      { readln;}
  53.       end;
  54.  
  55. procedure computelha;
  56.  
  57. begin
  58.  
  59. gha:= ghaoh+(gha24h-ghaoh+360)*ut1/24;
  60. lha:=gha-long;
  61. writeln ('lha (dd) = ',lha:8:8);
  62. lha:=degtorad (lha);
  63. writeln ('lha (rad) = ',lha:8:8);
  64. end;
  65.  
  66. procedure computedecl;
  67.  
  68. begin
  69.  
  70. decl:=decloh +(decl24h-decloh)*ut1/24;
  71. writeln ('Decl (dd) = ',decl:8:8);
  72. decl:=degtorad (decl);
  73. writeln ('decl (rad) = ',decl:8:8);
  74. end;
  75.  
  76. {procedure computeaz (angle); }
  77.  
  78.  
  79. begin
  80.  
  81.  
  82. {procedure dec_to_dms (decdeg:real);
  83.  
  84. begin
  85. dd:=int(decdeg);
  86. writeln ('Degrees = ',dd:3:2);
  87. mm:=int(frac(decdeg)*60);
  88. Writeln ('Minutes = ',mm:2:2);
  89. ss:= ((frac(decdeg)*60)-mm)*60;
  90. writeln('seconds = ',ss:2:2);
  91. ddmmss:= dd+(mm/100)+ (ss/10000);
  92. writeln('ddmmss= ',ddmmss:8:4);
  93.  readln;
  94.  end;   }
  95.  
  96.  
  97.  
  98.  
  99. begin
  100.  
  101.  writeln ('COMPUTING SOLAR/STAR OBSERVATION FOR AZIMUTH');
  102.  writeln ('Enter Semidiameter of sun. Enter 0.0 for star data');
  103.  readln (sdia);
  104.  writeln ('Enter GHA0H');
  105.  readln (ghaoh);
  106.  writeln ('Enter GHA24H');
  107.  read(gha24h);
  108.  writeln ('Enter DEC0HR');
  109.  readln (decloh);
  110.  writeln ('Enter DECH24H');
  111.  read(decl24h);
  112.  writeln ('Enter UT1 of observation');
  113.  readln (ut1);
  114.  {writeln('Enter circle reading on mark');
  115.  readln (crm);
  116.  writeln ('Enter circle reading on sun/star');
  117.  readln (crs);}
  118.  writeln ('Enter longitude');
  119.  read (long);
  120.  writeln ('Enter latitude');
  121.  readln (lat);
  122.  ddmmss:= sdia;
  123.  dms_to_dec (ddmmss);
  124.  sdia:=decdeg;
  125.  ddmmss:= ghaoh;
  126.  dms_to_dec (ddmmss);
  127.  ghaoh:= decdeg;
  128.  ddmmss:=gha24h;
  129.  dms_to_dec (ddmmss);
  130.  gha24h:= decdeg;
  131.  ddmmss:=decloh;
  132.  dms_to_dec (ddmmss);
  133.  decloh:=decdeg;
  134.  ddmmss:=decl24h;
  135.  dms_to_dec (ddmmss);
  136.  decl24h:=decdeg;
  137.  ddmmss:=ut1;
  138.  dms_to_dec (ddmmss);
  139.  ut1:=decdeg;
  140.  ddmmss:=crm;
  141.  dms_to_dec (ddmmss);
  142.  crm:=decdeg;
  143.  ddmmss:=crs;
  144.  dms_to_dec (crs);
  145.  crs:=decdeg;
  146.  ddmmss:=lat;
  147.  dms_to_dec (ddmmss);
  148.  lat:=decdeg;
  149.  ddmmss:=long;
  150.  dms_to_dec (ddmmss);
  151.  long:=decdeg;
  152.  
  153.  {writeln(sdia:8:4);
  154.  writeln (ghaoh:8:4);
  155.  writeln (gha24h:8:4);
  156.  writeln (decloh:8:4);
  157.  writeln (decl24h:8:4);
  158.  writeln (ut1:8:4);
  159.  writeln (crm:8:4);
  160.  writeln (crs:8:4);
  161.  readln;}
  162.  computelha;
  163.  computedecl;
  164.  
  165.  lat:=degtorad (lat);
  166.  long:=degtorad (long);
  167.  
  168.  a:=-sin(lha);
  169.  b:=(cos(lat)*tan(decl))-(sin(lat)*cos(lha));
  170.  az:=arctan (a/b);
  171.  az:= radtodeg (az);
  172.  
  173.  if az <0 then az:=360+az;
  174.  writeln ('az= ',az:8:5);
  175.  readln;
  176.  
  177.  
  178.  { Writeln ('input angle in ddd.mmss format.');
  179.   readln (ddmmss);
  180.   dms_to_dec (ddmmss);
  181.   readln;
  182.   writeln ('Will convert back to ddd.mm.ss format');
  183.   dec_to_dms (decdeg);
  184.   readln;}
  185. end;
  186.  
  187. end.

FPnewbie

  • New member
  • *
  • Posts: 6
Re: Program unexpected pause
« Reply #4 on: March 24, 2021, 03:16:07 am »
Thank you!

 

TinyPortal © 2005-2018