Lazarus

Free Pascal => Beginners => Topic started by: NightWing on May 08, 2018, 12:03:40 am

Title: A lot If-Else-If
Post by: NightWing on May 08, 2018, 12:03:40 am
Hello, i got this code and idk why show me that.. I try to make an calculator of bytes to another one.
I can only use nested if & else, already add & delete so much ' ; ' trying to make it work but i don't know how.
{
>> fpc puff.pas                                                                 

Free Pascal Compiler version 3.0.4 [2017/10/02] for x86_64
Copyright (c) 1993-2017 by Florian Klaempfl and others
Target OS: Linux for x86-64
Compiling puff.pas
puff.pas(320,5) Fatal: Syntax error, ";" expected but "ELSE" found
Fatal: Compilation aborted
Error: /usr/bin/ppcx64 returned an error exitcode

}

I'm begginer and no, it's not homework.. I only try to learn & understand pascal.. This forum is my last resource     :(   :(  :'(
(compiled on CentOs' 7 terminal)
Title: Re: i don't know why
Post by: Kays on May 08, 2018, 12:42:52 am
[…] i got this code […]
OMG. “Someone else gave it to me.” … Sure. (x.X)

I threw the source code into ptop(1). Maybe this'll help you identify the problem. I won't read 300 lines of code doing this for you. Especially since I have difficulties determining “should at this line be an end, or not?” This is up to you.
Title: Re: i don't know why
Post by: Josh on May 08, 2018, 12:56:09 am
I tried formatting the code, which helps high light where things are a miss
I got so far and ran out of indentation. The case statement is not completed, sorry spent too much time formatting code to try to work out whats wrong. Hopefully you can work out whats wrong, it falls apart around line 298 the 'end' statement is ending the case item.
Code: Pascal  [Select][+][-]
  1. program puff;
  2. uses crt;
  3. var
  4.         mercurio, tierra, marte, jupiter, saturno, urano, neptuno, neptunoB, neptunoK, neptunoM, neptunoG, neptunoT, neptunoP, neptunoMB, neptunoMK, neptunoMM, neptunoMG, neptunoMT, neptunoMP, pluton : int64;
  5.         venus : string; { o char}
  6. begin
  7.   clrscr;
  8.   writeln('Hello there!');
  9.   writeln('Ingrese la cantidad de bytes a convertir: ');
  10.   readln(mercurio);
  11.  
  12.   writeln('');
  13.   writeln('¿A que unidad los quiere convertir?');
  14.   writeln(' k = kilobytes, m = megabytes, g = gigabytes, t = terabytes');
  15.   writeln(' p = petabytes, c = exacto / -v, e = salir ');
  16.   readln(venus);
  17.  
  18.   case venus of
  19.  
  20.     { Convertir a kilobytes }
  21.  
  22.     'k' : begin
  23.             tierra := mercurio div 1024;
  24.             {pluton := tierra mod 1024;}
  25.             writeln('El resultado de convertir ',mercurio,' bytes a kilobytes es: ',tierra,'.');
  26.           end;
  27.  
  28.     { Convertir a megabytes }
  29.  
  30.     'm' : begin
  31.             marte := mercurio div 1048576;
  32.             {pluton := tierra mod 1024;}
  33.             writeln('El resultado de convertir ',mercurio,' bytes a megabytes es: ',marte,'.');
  34.           end;
  35.  
  36.     { Convertir a gigabytes }
  37.  
  38.     'g' : begin
  39.             jupiter := mercurio div 1073741824;
  40.             {pluton := tierra mod 1024;}
  41.             writeln('El resultado de convertir ',mercurio,' bytes a megabytes es: ',jupiter,'.');
  42.           end;
  43.  
  44.     { Convertir a terabytes }
  45.  
  46.     't' : begin
  47.             saturno := mercurio div 1099511627776;
  48.             {pluton := tierra mod 1024;}
  49.             writeln('El resultado de convertir ',mercurio,' bytes a terabytes es: ',saturno,'.');
  50.           end;
  51.  
  52.     { Convertir a petabytes }
  53.  
  54.     'p' : begin
  55.             urano := mercurio div 1125899906842624;
  56.             {pluton := tierra mod 1024;}
  57.             writeln('El resultado de convertir ',mercurio,' bytes a petabytes es: ',urano,'.');
  58.           end;
  59.  
  60.     { Conversion exacta / -v }
  61.  
  62.     'c' : begin
  63.  
  64.             { /*************************************************************************/ }
  65.                                 { Petabytes Root }
  66.             { /*************************************************************************/ }
  67.  
  68.             if (mercurio >= 1125899906842624) then
  69.             begin
  70.               neptunoP := mercurio div 1125899906842624;
  71.               neptunoMP := mercurio mod 1125899906842624;
  72.  
  73.               { Solo para verificar que no se ingreso una cantidad exacta de petabytes }
  74.               if (neptunoMP > 0) then
  75.               begin
  76.                 { Terabyte }
  77.                 if (neptunoMP >= 1099511627776) and (neptunoMP < 1125899906842624) then
  78.                 begin
  79.                   neptunoT := neptunoMP div 1099511627776;
  80.                   neptunoMT := neptunoMP mod 1099511627776;
  81.  
  82.                   { Gigabyte }
  83.                   if (neptunoMT >= 1073741824) then
  84.                   begin
  85.                     { codigo si el residuo es mayor que un terabyte }
  86.                     neptunoG := neptunoMT div 1073741824;               { 1073741024: Valor minimo para ser considerado terabytes }
  87.                     neptunoMG := neptunoMT mod 1073741824;
  88.  
  89.  
  90.                     { falta formula para saber si no es un terabyte exacto }
  91.                     { if MG > 0 then .. && empieza la formula siguiente de megabytes }
  92.  
  93.                     { Megabyte }
  94.                     if (neptunoMG > 1048576) then
  95.                     begin
  96.                       {codigo si el residuo es mayor que un gigabyte}
  97.                       neptunoM := neptunoMG div 1048576;
  98.                       neptunoMM := neptunoMG mod 1048576;
  99.  
  100.                       { Kilobyte }
  101.                       if (neptunoMM >= 1024) then
  102.                       begin
  103.                         {codigo si el residuo es mayor que un megabyte}
  104.                         neptunoK := neptunoMM div 1024;
  105.                         neptunoMK := neptunoMM mod 1024;
  106.  
  107.                         {  Byte }
  108.                         if (neptunoMK < 1024) then
  109.                         begin
  110.                           {codigo si el residuo es mayor que un kilobyte}
  111.                           neptunoB := neptunoMK;
  112.  
  113.                           {neptunoMB := neptunoMK mod 1024;}
  114.                         end;
  115.                       end
  116.  
  117.                       { Byte }
  118.                       else if (neptunoMM < 1024) then
  119.                       begin
  120.                         {codigo si el residuo es mayor que un kilobyte}
  121.                         neptunoB := neptunoMM;
  122.                         {neptunoMB := neptunoMM mod 1024;}
  123.                       End
  124.                     end
  125.  
  126.                     { Kilobyte }
  127.  
  128.                     else if (neptunoMG >= 1024) then
  129.                     begin
  130.                       {codigo si el residuo es mayor que un megabyte}
  131.                       neptunoK := neptunoMG div 1024;
  132.                       neptunoMK := neptunoMG mod 1024;
  133.  
  134.                       { Byte }
  135.  
  136.                       if (neptunoMK < 1024) then
  137.                       begin
  138.                         {codigo si el residuo es mayor que un kilobyte}
  139.                         neptunoB := neptunoMK;
  140.                       End;
  141.                     end
  142.  
  143.                     { Byte }
  144.                     else if (neptunoMG < 1024) then
  145.                     begin
  146.                       neptunoB := neptunoMG;
  147.                     end      
  148.                   end
  149.  
  150.                   { Megabyte }
  151.                   else if (neptunoMT > 1048576) then
  152.                   begin
  153.                     {codigo si el residuo es mayor que un gigabyte}
  154.                     neptunoM := neptunoMT div 1048576;
  155.                     neptunoMM := neptunoMT mod 1048576;
  156.  
  157.                     { Kilobyte }
  158.                     if (neptunoMM >= 1024) then
  159.                     begin
  160.                       {codigo si el residuo es mayor que un megabyte}
  161.                       neptunoK := neptunoMM div 1024;
  162.                       neptunoMK := neptunoMM mod 1024;
  163.  
  164.                       { Byte }
  165.                       if (neptunoMK < 1024) then
  166.                       begin
  167.                         {codigo si el residuo es mayor que un kilobyte}
  168.                         neptunoB := neptunoMK;
  169.                         {neptunoMB := neptunoMK mod 1024;}
  170.                       End;
  171.                     end
  172.  
  173.                     { Byte }
  174.                     else if (neptunoMM < 1024) then
  175.                     begin
  176.                       {codigo si el residuo es mayor que un kilobyte}
  177.                       neptunoB := neptunoMM;
  178.                       {neptunoMB := neptunoMM mod 1024;}
  179.                     end
  180.                   end
  181.  
  182.                   { Kilobyte }
  183.                   else if (neptunoMT > 1024) then
  184.                   begin
  185.                     {codigo si el residuo es mayor que un megabyte}
  186.                     neptunoK := neptunoMT div 1024;
  187.                     neptunoMK := neptunoMT mod 1024;
  188.  
  189.                     {  Byte }
  190.                     if (neptunoMK < 1024) then
  191.                     begin
  192.                       {codigo si el residuo es mayor que un kilobyte}
  193.                       neptunoB := neptunoMK;
  194.                       {neptunoMB := neptunoMK mod 1024;}
  195.                     end;
  196.                   end
  197.  
  198.                   { Byte }
  199.                   else if (neptunoMT < 1024) then
  200.                   begin
  201.                     {codigo si el residuo es mayor que un kilobyte}
  202.                     neptunoB := neptunoMT;
  203.                     {neptunoMB := neptunoMT mod 1024;}
  204.                   end
  205.                 end
  206.  
  207.                 { Gigabytes d Petabytes}
  208.                 else if (neptunoMP > 1073741824) then
  209.                 begin
  210.                   {codigo si el residuo es mayor que un Gigabyte}
  211.                   neptunoG := neptunoMP div 1073741824;
  212.                   neptunoMG := neptunoMP mod 1073741824;
  213.  
  214.                   { Megabyte }
  215.                   if (neptunoMG > 1048576) then
  216.                   begin
  217.                     {codigo si el residuo es mayor que un Megabyte}
  218.                     neptunoM := neptunoMG div 1048576;
  219.                     neptunoMM := neptunoMG mod 1048576;
  220.  
  221.                     { Kilobyte }
  222.                     if (neptunoMM >= 1024) then
  223.                     begin
  224.                       {codigo si el residuo es mayor que un Kilobyte}
  225.                       neptunoK := neptunoMM div 1024;
  226.                       neptunoMK := neptunoMM mod 1024;
  227.  
  228.                       {  Byte }
  229.                       if (neptunoMK < 1024) then
  230.                       begin
  231.                         {codigo si el residuo es mayor que un Byte}
  232.                         neptunoB := neptunoMK;
  233.                         {neptunoMB := neptunoMK mod 1024;}
  234.                       end;
  235.                     end
  236.  
  237.                     {  Byte }
  238.                     else if (neptunoMM < 1024) then
  239.                     {codigo si el residuo es mayor que un kilobyte}
  240.                     neptunoB := neptunoMM;
  241.                     {neptunoMB := neptunoMM mod 1024;}
  242.                   end
  243.                 end
  244.  
  245.                 { Kilobyte }
  246.                 else if (neptunoMG >= 1024) then
  247.                 begin
  248.                   {codigo si el residuo es mayor que un megabyte}
  249.                   neptunoK := neptunoMG div 1024;
  250.                   neptunoMK := neptunoMG mod 1024;
  251.  
  252.                   {  Byte }
  253.                   if (neptunoMK < 1024) then
  254.                   begin
  255.                     {codigo si el residuo es mayor que un kilobyte}
  256.                     neptunoB := neptunoMK;
  257.                     {neptunoMB := neptunoMK mod 1024;}
  258.                   end;
  259.                 end
  260.  
  261.                 { Byte }
  262.                 else if (neptunoMG < 1024) then
  263.                   {codigo si el residuo es mayor que un kilobyte}
  264.                   neptunoB := neptunoMG;
  265.                   {neptunoMB := neptunoMG mod 1024;}
  266.               end
  267.             end
  268.  
  269.             { Megabyte d Petabytes }
  270.             else if (neptunoMP > 1048576) then
  271.             begin
  272.               {codigo si el residuo es mayor que un gigabyte}
  273.               neptunoM := neptunoMP div 1048576;
  274.               neptunoMM := neptunoMP mod 1048576;
  275.  
  276.               { Kilobyte }
  277.               if (neptunoMM >= 1024) then
  278.               begin
  279.                 {codigo si el residuo es mayor que un megabyte}
  280.                 neptunoK := neptunoMM div 1024;
  281.                 neptunoMK := neptunoMM mod 1024;
  282.  
  283.                 {  Byte }
  284.                 if (neptunoMK < 1024) then
  285.                 begin
  286.                   {codigo si el residuo es mayor que un kilobyte}
  287.                   neptunoB := neptunoMK;
  288.                   {neptunoMB := neptunoMK mod 1024;}
  289.                 end;
  290.               end
  291.  
  292.               {  Byte }
  293.               else if (neptunoMM < 1024) then
  294.                 {codigo si el residuo es mayor que un kilobyte}
  295.                 neptunoB := neptunoMM;
  296.                 {neptunoMB := neptunoMM mod 1024;}
  297.             end
  298.     end        // end of case c
  299.  
  300.     { Kilobyte d Petabytes}
  301.     else if (neptunoMP > 1024) then
  302.     begin
  303.       {codigo si el residuo es mayor que un megabyte}
  304.       neptunoK := neptunoMP div 1024;
  305.       neptunoMK := neptunoMP mod 1024;
  306.  
  307.       { Byte }
  308.       if (neptunoMK < 1024) then
  309.       begin
  310.         neptunoB := neptunoMK;
  311.       End;
  312.     end
  313.  
  314.     { Byte d Petabytes }
  315.     else if (neptunoMP < 1024) then
  316.     begin
  317.       {codigo si el residuo es menor que un kilobyte}
  318.       neptunoB := neptunoMP
  319.       {neptunoMB := neptunoMP mod 1024;}
  320.     end
  321.   end       // end of case statment
  322.  
  323.   else if (mercurio <1) then
  324.     writeln('Ha digitado la cantidad de ',mercurio,' bytes, para un numero exacto de ',neptunoP,' Petabytes');
  325. end     // run out of indentation something wrong
  326.  
  327.         { /*************************************************************************/ }
  328.  
  329.         { aqui termina el universo de terabyte y comienza el surgimiento del reino de Terabyte }
  330.  
  331.         { /*************************************************************************/ }
  332.                                 { Terabyte Root }
  333.         { /*************************************************************************/ }
  334.  
  335.                         else if (mercurio >= 1099511627776) then
  336.                         begin
  337.                                 neptunoT := mercurio div 1099511627776;
  338.                                 neptunoMT := mercurio mod 1099511627776;
  339.  
  340.                                 { Solo para verificar que no se ingreso una cantidad exacta de Terabytes }
  341.                                 if (neptunoMT > 0) then
  342.                                 begin
  343.  
  344.                                         { Gigabyte }
  345.                                         if (neptunoMT > 1073741824) then
  346.                                         begin
  347.                                                 {codigo si el residuo es mayor que un terabyte}
  348.                                                 neptunoG := neptunoMT div 1073741824;
  349.                                                 neptunoMG := neptunoMT mod 1073741824;
  350.  
  351.                                                 { Megabyte }
  352.                                                 if (neptunoMG > 1048576) then
  353.                                                 begin
  354.                                                         {codigo si el residuo es mayor que un gigabyte}
  355.                                                         neptunoM := neptunoMG div 1048576;
  356.                                                         neptunoMM := neptunoMG mod 1048576;
  357.  
  358.                                                         { Kilobyte }
  359.                                                         if (neptunoMM >= 1024) then
  360.                                                         begin
  361.                                                                 {codigo si el residuo es mayor que un megabyte}
  362.                                                                 neptunoK := neptunoMM div 1024;
  363.                                                                 neptunoMK := neptunoMM mod 1024;
  364.  
  365.                                                                 {  Byte }
  366.                                                                 if (neptunoMK < 1024) then
  367.                                                                 begin
  368.                                                                         {codigo si el residuo es mayor que un kilobyte}
  369.                                                                         neptunoB := neptunoMK;
  370.                                                                         {neptunoMB := neptunoMK mod 1024;}
  371.                                                                 end;
  372.                                                         end
  373.  
  374.                                                         { Byte }
  375.                                                         else if (neptunoMM < 1024) then
  376.                                                         begin
  377.                                                                 {codigo si el residuo es mayor que un kilobyte}
  378.                                                                 neptunoB := neptunoMM;
  379.                                                                 {neptunoMB := neptunoMM mod 1024;}
  380.                                                         end;
  381.                                                 end
  382.  
  383.                                                 { Kilobyte }
  384.                                                 else if (neptunoMG >= 1024) then
  385.                                                 begin
  386.                                                         {codigo si el residuo es mayor que un megabyte}
  387.                                                         neptunoK := neptunoMG div 1024;
  388.                                                         neptunoMK := neptunoMG mod 1024;
  389.  
  390.                                                         {  Byte }
  391.                                                         if (neptunoMK < 1024) then
  392.                                                         begin
  393.                                                                 {codigo si el residuo es mayor que un kilobyte}
  394.                                                                 neptunoB := neptunoMK;
  395.                                                                 {neptunoMB := neptunoMK mod 1024;}
  396.                                                         end;
  397.                                                 end
  398.  
  399.                                                 {  Byte }
  400.                                                 else if (neptunoMG < 1024) then
  401.                                                         {codigo si el residuo es mayor que un kilobyte}
  402.                                                         neptunoB := neptunoMG;
  403.                                                         {neptunoMB := neptunoMG mod 1024;}
  404.                                                 end;
  405.                                         end
  406.  
  407.                                         { Megabyte }
  408.                                         else if (neptunoMT > 1048576) then
  409.                                         begin
  410.                                                 {codigo si el residuo es mayor que un gigabyte}
  411.                                                 neptunoM := neptunoMT div 1048576;
  412.                                                 neptunoMM := neptunoMT mod 1048576;
  413.  
  414.                                                 { Kilobyte }
  415.                                                 if (neptunoMM >= 1024) then
  416.                                                 begin
  417.                                                         {codigo si el residuo es mayor que un megabyte}
  418.                                                         neptunoK := neptunoMM div 1024;
  419.                                                         neptunoMK := neptunoMM mod 1024;
  420.  
  421.                                                         { Byte }
  422.                                                         if (neptunoMK < 1024) then
  423.                                                         begin
  424.                                                                 {codigo si el residuo es mayor que un kilobyte}
  425.                                                                 neptunoB := neptunoMK;
  426.                                                                 {neptunoMB := neptunoMK mod 1024;}
  427.                                                         end;
  428.                                                 end
  429.  
  430.                                                 {  Byte }
  431.                                                 else if (neptunoMM < 1024) then
  432.                                                 begin
  433.                                                         {codigo si el residuo es mayor que un kilobyte}
  434.                                                         neptunoB := neptunoMM;
  435.                                                         {neptunoMB := neptunoMM mod 1024;}
  436.                                                 end;
  437.                                         end
  438.  
  439.                                         { Kilobyte }
  440.                                         else if (neptunoMT > 1024) then
  441.                                         begin
  442.                                                 {codigo si el residuo es mayor que un megabyte}
  443.                                                 neptunoK := neptunoMT div 1024;
  444.                                                 neptunoMK := neptunoMT mod 1024;
  445.  
  446.                                                 {  Byte }
  447.                                                 if (neptunoMK < 1024) then
  448.                                                 begin
  449.                                                         {codigo si el residuo es mayor que un kilobyte}
  450.                                                         neptunoB := neptunoMK;
  451.                                                         {neptunoMB := neptunoMK mod 1024;}
  452.                                                 end;
  453.                                         end
  454.  
  455.                                         { Byte }
  456.                                         else if (neptunoMT < 1024) then
  457.                                         begin
  458.                                                 {codigo si el residuo es mayor que un kilobyte}
  459.                                                 neptunoB := neptunoMT;
  460.                                                 {neptunoMB := neptunoMT mod 1024;}
  461.                                         end;
  462.                                 end
  463.                                 else
  464.                                 begin
  465.                                         writeln('Ha digitado la cantidad de ',mercurio,' bytes, para un numero exacto de ',neptunoT,' Terabytes');
  466.                                 end;
  467.                         end
  468.  
  469.         { /*************************************************************************/ }
  470.                                 { Gigabytes Root }
  471.         { /*************************************************************************/ }
  472.  
  473.                         else if (mercurio > 1073741824) then
  474.                         begin
  475.                                 {codigo si el residuo es mayor que un terabyte}
  476.                                 neptunoG := mercurio div 1073741824;
  477.                                 neptunoMG := mercurio mod 1073741824;
  478.  
  479.                                 { Solo para verificar que no se ingreso una cantidad exacta de Gigabytes }
  480.                                 if (neptunoMG > 0) then
  481.                                 begin
  482.                                         { Megabyte }
  483.                                         if (neptunoMG > 1048576) then
  484.                                         begin
  485.                                                 {codigo si el residuo es mayor que un gigabyte}
  486.                                                 neptunoM := neptunoMG div 1048576;
  487.                                                 neptunoMM := neptunoMG mod 1048576;
  488.  
  489.                                                 { Kilobyte }
  490.                                                 if (neptunoMM >= 1024) then
  491.                                                 begin
  492.                                                         {codigo si el residuo es mayor que un megabyte}
  493.                                                         neptunoK := neptunoMM div 1024;
  494.                                                         neptunoMK := neptunoMM mod 1024;
  495.  
  496.                                                         {  Byte }
  497.                                                         if (neptunoMK < 1024) then
  498.                                                         begin
  499.                                                                 {codigo si el residuo es mayor que un kilobyte}
  500.                                                                 neptunoB := neptunoMK;
  501.                                                                 {neptunoMB := neptunoMK mod 1024;}
  502.                                                         end;
  503.                                                 end
  504.  
  505.                                                 { Byte }
  506.                                                 else if (neptunoMM < 1024) then
  507.                                                 begin
  508.                                                         {codigo si el residuo es mayor que un kilobyte}
  509.                                                         neptunoB := neptunoMM;
  510.                                                         {neptunoMB := neptunoMM mod 1024;}
  511.                                                 end;
  512.                                         end
  513.  
  514.                                         { Kilobyte }
  515.                                         else if (neptunoMG >= 1024) then
  516.                                         begin
  517.                                                 {codigo si el residuo es mayor que un megabyte}
  518.                                                 neptunoK := neptunoMG div 1024;
  519.                                                 neptunoMK := neptunoMG mod 1024;
  520.  
  521.                                                 {  Byte }
  522.                                                 if (neptunoMK < 1024) then
  523.                                                 begin
  524.                                                         {codigo si el residuo es mayor que un kilobyte}
  525.                                                         neptunoB := neptunoMK;
  526.                                                         {neptunoMB := neptunoMK mod 1024;}
  527.                                                 end;
  528.                                         end
  529.  
  530.                                         {  Byte }
  531.                                         else if (neptunoMG < 1024) then
  532.                                         begin
  533.                                                 {codigo si el residuo es mayor que un kilobyte}
  534.                                                 neptunoB := neptunoMG;
  535.                                                 {neptunoMB := neptunoMG mod 1024;}
  536.                                         end;
  537.                                 end
  538.                                 else
  539.                                 begin
  540.                                         writeln('Ha digitado la cantidad de ',mercurio,' bytes, para un numero exacto de ',neptunoT,' gIGAbytes');
  541.                                 end;
  542.                         end
  543.  
  544.         { /*************************************************************************/ }
  545.                                 { Megabyte Root }
  546.         { /*************************************************************************/ }
  547.  
  548.                         else if (mercurio > 1048576) then
  549.                         begin
  550.                                 {codigo si el residuo es mayor que un gigabyte}
  551.                                 neptunoM := mercurio div 1048576;
  552.                                 neptunoMM := mercurio mod 1048576;
  553.  
  554.                                 { Solo para verificar que no se ingreso una cantidad exacta de petabytes }
  555.                                 if (neptunoMP > 0) then
  556.                                 begin
  557.                                         { Kilobyte }
  558.                                         if (neptunoMM >= 1024) then
  559.                                         begin
  560.                                                 {codigo si el residuo es mayor que un megabyte}
  561.                                                 neptunoK := neptunoMM div 1024;
  562.                                                 neptunoMK := neptunoMM mod 1024;
  563.  
  564.                                                 {  Byte }
  565.                                                 if (neptunoMK < 1024) then
  566.                                                 begin
  567.                                                         {codigo si el residuo es mayor que un kilobyte}
  568.                                                         neptunoB := neptunoMK;
  569.                                                         {neptunoMB := neptunoMK mod 1024;}
  570.                                                 end;
  571.                                         end
  572.  
  573.                                         { Byte }
  574.                                         else if (neptunoMM < 1024) then
  575.                                         begin
  576.                                                 {codigo si el residuo es mayor que un kilobyte}
  577.                                                 neptunoB := neptunoMM;
  578.                                                 {neptunoMB := neptunoMM mod 1024;}
  579.                                         end;
  580.                                 end
  581.                                 else
  582.                                 begin
  583.                                         writeln('Ha digitado la cantidad de ',mercurio,' bytes, para un numero exacto de ',neptunoT,' Gigabytes');
  584.                                 end;
  585.                         end
  586.  
  587.         { /*************************************************************************/ }
  588.                         { Kilobyte Root }
  589.         { /*************************************************************************/ }
  590.  
  591.                         else if (mercurio >= 1024) then
  592.                         begin
  593.                                 {codigo si el residuo es mayor que un megabyte}
  594.                                 neptunoK := mercurio div 1024;
  595.                                 neptunoMK := mercurio mod 1024;
  596.  
  597.                                 {  Byte }
  598.                                 if (neptunoMK < 1024) then
  599.                                 begin
  600.                                         {codigo si el residuo es mayor que un kilobyte}
  601.                                         neptunoB := neptunoMK;
  602.                                         {neptunoMB := neptunoMK mod 1024;}
  603.                                 end;
  604.                         end
  605.  
  606.         { /*************************************************************************/ }
  607.                         { Byte Root }
  608.         { /*************************************************************************/ }
  609.  
  610.                         else if (mercurio < 1024) then
  611.                         begin
  612.                                 {codigo si el residuo es mayor que un kilobyte}
  613.                                 neptunoB := mercurio;
  614.                                 {neptunoMB := mercurio mod 1024;}
  615.                         end
  616.                 {/*******************************************************/}
  617.  
  618.  
  619.                         { Rara ocasion en la que ingresen una cantidad exacta de bytes de un petabyte }
  620.                         else
  621.                         begin
  622.                                 writeln('La conversion de ',mercurio,' bytes es: ',neptunoP,' petabytes exactos.');
  623.                         end;
  624.                 end:
  625.  
  626.                 'e' : begin
  627.                         writeln('Hasta luego!')
  628.                 end;
  629.         end;
  630.  
  631.         writeln('END_OF_FILE__');
  632. end.
  633.  
  634.  
Title: Re: i don't know why
Post by: NightWing on May 08, 2018, 03:40:21 pm
Forget to write the question, in the code use several if nested with else if

How does the ' ; ' law apply in several nested if-else-if ?, nowhere in the wiki did I find an example with more than one 'else if' and in browsers they show the same simple examples

What would be the correct way to place the ';' at the end of each condition?

ie:
Code: Pascal  [Select][+][-]
  1. begin
  2. if (x > y) then
  3.     begin
  4.         write ('X is bigger');
  5.         z := x+y;
  6.         if (z > x) then
  7.             begin
  8.                 writeln('Z is bigger');
  9.             end
  10.         else
  11.             begin
  12.                 writeln('X still bigger');
  13.             end;
  14.     end
  15. else if (x > y) then
  16.     begin
  17.          writeln ('Y is bigger');
  18.      end
  19. else if (x == y) then
  20.     begin
  21.          writeln ('x & y are the same');
  22.      end
  23. else
  24.     begin
  25.         writeln('something wrong happend');
  26.     end;
  27. end.
  28.  
Title: Re: i don't know why
Post by: Handoko on May 08, 2018, 04:03:03 pm
Rules:
- There must be no ; symbol before else
- The total count of begin must be equals to the total count of end

I haven't tested your code. I could be wrong but my eye-inspection told me you forgot a begin for the if clause on the line #290. See the image below:
Title: Re: i don't know why
Post by: Josh on May 08, 2018, 04:07:45 pm
Hi

You may find it easier if you block your if then ...... else .... with begin end; it makes it easier to follow ie

Code: Pascal  [Select][+][-]
  1. if {Condition A} then
  2. begin
  3.   if {Condition B} then
  4.   begin
  5.     .....
  6.   end   // no ; because else is following
  7.   else
  8.   begin   {Else Section of Condition B}
  9.     if {Condition C} then
  10.     begin
  11.       .....
  12.       if {Condition D} then
  13.       begin
  14.         .......
  15.         if ??????? then
  16.         begin
  17.           ......
  18.         end
  19.         else
  20.         begin
  21.           if ?????????? then
  22.           begin
  23.             ......
  24.           end
  25.           else
  26.           begin
  27.             ......
  28.           end;
  29.         end;
  30.       end   // no ; else following
  31.       else {Else Section of Condition D}
  32.       begin
  33.         if ????????? then
  34.         begin
  35.           ....
  36.         end
  37.         else
  38.         begin
  39.           if ?????????? then
  40.           begin
  41.             .....
  42.           end
  43.           else
  44.           begin
  45.             ......
  46.           end;
  47.         end;
  48.       end; {End Section of Condition D}
  49.     end; {End Section of Condition C}
  50.   end; {End Section of Condition B}
  51. end; {End of Condition A}        
  52.  

Code: Pascal  [Select][+][-]
  1. program Project1;
  2. {$mode objfpc}{$H+}
  3. uses
  4.   {$IFDEF UNIX}{$IFDEF UseCThreads}
  5.   cthreads,
  6.   {$ENDIF}{$ENDIF}
  7.   Classes
  8.   { you can add units after this };
  9.  
  10. var x:integer=2;
  11.     y:integer=4;
  12.     z:integer=0;
  13.  
  14. begin
  15.   if (x > y) then
  16.   begin
  17.     write ('X is bigger');
  18.     z := x+y;
  19.     if (z > x) then
  20.     begin
  21.       writeln('Z is bigger');
  22.     end
  23.     else
  24.     begin
  25.       writeln('X still bigger');
  26.     end;
  27.   end      // no ; this allows an else statement ie if then else;
  28.   else // i think you want the whole next section executed in th else block; so try using a begin end block
  29.   begin // added
  30.     if (x > y) then
  31.     begin
  32.       writeln ('Y is bigger');
  33.     end
  34.     else
  35.     begin // added
  36.       if (x=y) then  // changed from == to =
  37.       begin
  38.         writeln ('x & y are the same');
  39.       end
  40.       else
  41.       begin
  42.         writeln('something wrong happend');
  43.       end;
  44.     end; // added
  45.   end; // end of else section so ;
  46. end.
  47.  
Title: Re: i don't know why
Post by: Handoko on May 08, 2018, 04:19:50 pm
Or use colored outline of source structure feature, which is already available since Lazarus 1.8.0. Read more:
http://wiki.freepascal.org/Lazarus_IDE_Tools#Outline

But I personally will try to rewrite the code if the if clause has more than 3 levels, maybe try other logics or move some parts of them to a local nested procedure.
Title: Re: i don't know why
Post by: Zoran on May 08, 2018, 04:58:10 pm
This line with "==" will surely fail to compile:
Code: Pascal  [Select][+][-]
  1. else if (x == y) then
  2.  
Title: Re: i don't know why
Post by: Kays on May 10, 2018, 11:13:46 am
Why are you engaging him*her in such a bad design? Nested if-then-elses starting at a level of, prrprprp, four are getting ridiculous. And error-prone, as the OP's question proves.
Title: Re: i don't know why
Post by: Bart on May 10, 2018, 01:51:09 pm
This code seems to calculate how much Peta/Giga/Mega/Kilo-bytes a certain amount of bytes is?

The names of the variables confuse me: they seem to be the names of planets in the solar system?

Bart
Title: Re: i don't know why
Post by: Bart on May 10, 2018, 02:23:15 pm
This may get you started?

Code: Pascal  [Select][+][-]
  1. program Project1;
  2. {$mode objfpc}
  3. {$h+}
  4. uses
  5.   SysUtils;
  6.  
  7. const
  8.   Kilo = 1024;
  9.   Mega = 1024 * Kilo;
  10.   Tera = 1024 * UInt64(Mega);
  11.   Peta = 1024 * UInt64(Tera);
  12.  
  13. procedure ConvertBytesToUnits(Amount: UInt64; out PetaBytes, TeraBytes, MegaBytes, KiloBytes, Bytes: UInt64);
  14. begin
  15.   PetaBytes := Amount div Peta;
  16.   Amount := Amount mod Peta;
  17.   TeraBytes := Amount div Tera;
  18.   Amount := Amount mod Tera;
  19.   MegaBytes := Amount div Mega;
  20.   Amount := Amount mod Mega;
  21.   KiloBytes := Amount div Kilo;
  22.   Bytes := Amount mod Kilo;
  23. end;
  24.  
  25. var
  26.   Count, PBytes, TBytes, MBytes, KBytes, Bytes: UInt64;
  27. begin
  28.   Count := Peta + 2*Tera + 3*Mega + 4*Kilo + 5;
  29.   ConvertBytesToUnits(Count, PBytes, TBytes, MBytes, KBytes, Bytes);
  30.   writeln(format('%u Bytes equals: %u PetaBytes, %u TeraBytes, %u MegaBytes, %u KiloBytes and %u Bytes',[Count,PBytes, TBytes, MBytes, KBytes, Bytes]));
  31. end.

Ouputs:
Code: [Select]
1101662261253 Bytes equals: 1 PetaBytes, 2 TeraBytes, 3 MegaBytes, 4 KiloBytes and 5 Bytes

Bart
Title: Re: i don't know why
Post by: af0815 on May 10, 2018, 03:03:47 pm
Hehe, if the guy use this without understanding, he will have an unwanted result :-)
Title: Re: i don't know why
Post by: howardpc on May 10, 2018, 04:38:43 pm
Ah, Bart, some sense at last. Rewrite from scratch.

Code such as NightWing was given is a total disaster.
No beginner should be presented with such useless code as that. There is no point formatting it correctly, or improving it or debugging it. Should be binned without hesitation. Multiple nested levels of conditional and case statements, myriads of global variables with insane names, use of crt unit ... Yuk! No wonder Pascal has a bad name in some quarters.
Title: Re: i don't know why
Post by: Handoko on May 10, 2018, 04:50:48 pm
We cannot expect beginners to write code like a professional, because he's just a beginner.

Binned away and present him with new code, without telling him what he did wrong, is not very helpful. He was learning about how to properly use if-then-else but showing him to use mod and div, is it helpful?
Title: Re: i don't know why
Post by: Bart on May 10, 2018, 07:24:53 pm
Hehe, if the guy use this without understanding, he will have an unwanted result :-)

Care to explain?

Binned away and present him with new code, without telling him what he did wrong, is not very helpful. He was learning about how to properly use if-then-else but showing him to use mod and div, is it helpful?

My piece of code was meant as a starting point for the "exact" case.
So, from my POV it was meant to be helpfull.

But if you think otherwise, please remind me not try to be of help to anyone on this forum anymore.

The non-exact cases are trivial, just divide by the proper base (Peta, Tera etc) to get, say 2090 bytes ~= 2 KB.
(Or use floating point arithmatic to get, say 2561 bytes~= 2.5 KB, whatever you like).

Using tons of if..then..else inside a case statement is just bad design. As others have pointed out, so no need to repeat that argument.
Using magic numbers as constants is bad design.
Using a block of code that is >> 1 screen probably is bad design.
Using variable names that make no sense to the meaning of the code is a WTF in it's own right.

Anyhow: we did not hear from TS again, so it's safe to say this was yet another homework assignment, and now his deadline has past.

Bart
Title: Re: i don't know why
Post by: howardpc on May 10, 2018, 07:56:57 pm
@Handoko
"binned away" ...
This was my reaction to this:

Hello, i got this code ...

I assumed NightWing had been given that code and was trying to make sense of it, and get it to compile, in the mistaken belief that it was a good or educational example with some merit.
I don't think a complete beginner in Pascal (which he wrote that he was) would come up with such a long and convoluted spaghetti-like offering as he shared as one of his first attempts.

It is important in this forum not only to offer good example code, that others can usefully profit from, but to be honest (without being gratuitously rude) about code that is badly designed, poorly formatted, and a potential maintenance nightmare. Apart from the fact that in this case the code was so badly thought out that the coder tripped himself up, so that it does not even get past the FPC parser and compile.
If people are offended when valid criticism is offered about the code they share here, then they should not post it where hundreds of programmers, many far more experienced than themselves, will view it.
Title: Re: i don't know why
Post by: af0815 on May 10, 2018, 09:03:02 pm
Hehe, if the guy use this without understanding, he will have an unwanted result :-)

Care to explain?

..
Simple: I have not read carefully enough ... i thought, it is weights of planets not bytes. -> my mistake.
After translating the first sentence from spanish to german, i see it.
Title: Re: i don't know why
Post by: Bart on May 10, 2018, 09:50:46 pm
... i thought, it is weights of planets not bytes. -> my mistake.

Exactly my thoughts when I glanced at the code the first time, also the reason I did not reply to the thread at that time, since I thought it had to do with astrology...

It's like obfuscated C  >:D

Bart
Title: Re: i don't know why
Post by: Kays on May 10, 2018, 10:47:19 pm
[…] i thought, it is weights of planets not bytes. -> my mistake.  […]
No, af0815, not weights, but masses are measured in Bytes. Didn't you know that?  :D More to chuckle about: triple F system (https://en.wikipedia.org/wiki/FFF_system).
Title: Re: i don't know why
Post by: soerensen3 on May 11, 2018, 12:08:55 am
First the Pascal file extension is lpr for projects or pas/pp for units, this way you get syntax highlighting. The features described below only work if the file is recognized as a pascal source by the editor.

To your initial problem: Lazarus has two really handy features which really help in this case:

1. Go to Options-> Editor -> Display -> Markup and Matches and select Outline (global)
Now it will highlight matching begin end [else] blocks. This also works other keywords. Now it should be easy to see where your problem is (Obviously an end in line 263)

2. You can auto format your source with Ctrl+D so you do not need  to do this by hand if you have a file you didn't write yourself. I doesn't seem to work on your code though. Probably because of the errors? I rarely use this feature myself.

Title: Re: i don't know why
Post by: Handoko on May 11, 2018, 03:42:39 am
@howardpc, @Bart

Please don't get me wrong. I also agree with you, that code is poorly written. But we should at least letting the OP know why it is not good, how to avoid to write code like that bad code. For example avoiding to use too many if-then-else levels, how to proper format code, try to use simpler logic to solve the problem, etc.

~ Peace ~

Note:
I am also a part-time teacher, some of my students were not very smart. That forces me to understand and see things from their view point.
Title: Re: i don't know why
Post by: Bart on May 11, 2018, 11:01:55 pm
~ Peace ~

Yeah man!

Bart
Title: Re: i don't know why
Post by: NightWing on May 20, 2018, 07:36:35 pm
Well,  I was very busy with supercomputing stuff and I did not have much time to work on the code but I managed to correct the if-else-if and I think I'm beginning to understand the use of the ';'
Thanks for your advice, they helped me to give me an idea, already compiles the program but I still need to correct the outputs of some orphaned variables

Code: Pascal  [Select][+][-]
  1. program puff;
  2. uses crt;
  3. var
  4.         mercurio, tierra, marte, jupiter, saturno, urano, neptuno, neptunoB, neptunoK, neptunoM, neptunoG, neptunoT, neptunoP, neptunoMB, neptunoMK, neptunoMM, neptunoMG, neptunoMT, neptunoMP, pluton : int64;               
  5.         venus : string;
  6. begin
  7.         writeln('Hello there!');
  8.         writeln('Ingrese la cantidad de bytes a convertir: ');
  9.         readln(mercurio);
  10.  
  11.         writeln('');
  12.         writeln('¿A que unidad los quiere convertir?');
  13.         writeln(' k = kilobytes, m = megabytes, g = gigabytes, t = terabytes, p = petabytes, c = exacto / -v, e = salir ');
  14.         readln(venus);
  15.  
  16.         case venus of
  17.  
  18.                 { Convertir a kilobytes }      
  19.  
  20.                 'k' : begin
  21.                         tierra := mercurio div 1024;
  22.                         {pluton := tierra mod 1024;}
  23.                         writeln('El resultado de convertir ',mercurio,' bytes a kilobytes es: ',tierra,'.');
  24.                 end;
  25.  
  26.                 { Convertir a megabytes }
  27.  
  28.                 'm' : begin
  29.                         marte := mercurio div 1048576;
  30.                         {pluton := tierra mod 1024;}
  31.                         writeln('El resultado de convertir ',mercurio,' bytes a megabytes es: ',marte,'.');
  32.                 end;
  33.  
  34.                 { Convertir a gigabytes }
  35.  
  36.                 'g' : begin
  37.                         jupiter := mercurio div 1073741824;
  38.                         {pluton := tierra mod 1024;}
  39.                         writeln('El resultado de convertir ',mercurio,' bytes a megabytes es: ',jupiter,'.');
  40.                 end;
  41.  
  42.                 { Convertir a terabytes }
  43.  
  44.                 't' : begin
  45.                         saturno := mercurio div 1099511627776;
  46.                         {pluton := tierra mod 1024;}
  47.                         writeln('El resultado de convertir ',mercurio,' bytes a terabytes es: ',saturno,'.');
  48.                 end;
  49.  
  50.                 { Convertir a petabytes }
  51.  
  52.                 'p' : begin
  53.                         urano := mercurio div 1125899906842624;
  54.                         {pluton := tierra mod 1024;}
  55.                         writeln('El resultado de convertir ',mercurio,' bytes a petabytes es: ',urano,'.');
  56.                 end;
  57.  
  58.                 { Conversion exacta / -v }
  59.  
  60.                 'c' : begin
  61.  
  62.         { /*************************************************************************/ }
  63.                                 { Petabytes Root }
  64.         { /*************************************************************************/ }
  65.  
  66.                         if (mercurio >= 1125899906842624) then
  67.                         begin
  68.                                 neptunoP := mercurio div 1125899906842624;
  69.                                 neptunoMP := mercurio mod 1125899906842624;
  70.  
  71.                                 { Solo para verificar que no se ingreso una cantidad exacta de petabytes }
  72.                                 if (neptunoMP > 0) then
  73.                                 begin
  74.                                         { Terabyte }
  75.                                         if (neptunoMP >= 1099511627776) and (neptunoMP < 1125899906842624) then
  76.                                         begin
  77.                                                 neptunoT := neptunoMP div 1099511627776;
  78.                                                 neptunoMT := neptunoMP mod 1099511627776;                              
  79.                                                
  80.                                                 { Gigabyte }
  81.                                                 if (neptunoMT >= 1073741824) then
  82.                                                 begin                                          
  83.                                                         {codigo si el residuo es mayor que un terabyte}
  84.                                                         neptunoG := neptunoMT div 1073741824;
  85.                                                         neptunoMG := neptunoMT mod 1073741824;
  86.                                                        
  87.                                                         { Megabyte }    
  88.                                                         if (neptunoMG > 1048576) then
  89.                                                         begin                                          
  90.                                                                 {codigo si el residuo es mayor que un gigabyte}
  91.                                                                 neptunoM := neptunoMG div 1048576;
  92.                                                                 neptunoMM := neptunoMG mod 1048576;
  93.                                                                
  94.                                                                 { Kilobyte }           
  95.                                                                 if (neptunoMM >= 1024) then
  96.                                                                 begin
  97.                                                                         {codigo si el residuo es mayor que un megabyte}
  98.                                                                         neptunoK := neptunoMM div 1024;
  99.                                                                         neptunoMK := neptunoMM mod 1024;
  100.                                                                        
  101.                                                                         {  Byte }                      
  102.                                                                         if (neptunoMK < 1024) then
  103.                                                                         begin                                                          
  104.                                                                                 {codigo si el residuo es mayor que un kilobyte}
  105.                                                                                 neptunoB := neptunoMK;
  106.                                                                                 {neptunoMB := neptunoMK mod 1024;}
  107.                                                                         end;
  108.                                                                 end
  109.                                                                
  110.                                                                 { Byte }                       
  111.                                                                 else if (neptunoMM < 1024) then
  112.                                                                 begin
  113.                                                                         {codigo si el residuo es mayor que un kilobyte}
  114.                                                                         neptunoB := neptunoMM;
  115.                                                                         {neptunoMB := neptunoMM mod 1024;}
  116.                                                                 end
  117.                                                         end
  118.                                                        
  119.                                                         { Kilobyte }           
  120.                                                         else if (neptunoMG >= 1024) then
  121.                                                         begin                                                  
  122.                                                                 {codigo si el residuo es mayor que un megabyte}
  123.                                                                 neptunoK := neptunoMG div 1024;
  124.                                                                 neptunoMK := neptunoMG mod 1024;
  125.                                                
  126.                                                                 { Byte }                       
  127.                                                                 if (neptunoMK < 1024) then
  128.                                                                 begin
  129.                                                                         {codigo si el residuo es mayor que un kilobyte}
  130.                                                                         neptunoB := neptunoMK;
  131.                                                                 end;
  132.                                                         end
  133.                                                        
  134.                                                         { Byte }                       
  135.                                                         else if (neptunoMG < 1024) then
  136.                                                         begin
  137.                                                                 neptunoB := neptunoMG;
  138.                                                         end
  139.                                                 end
  140.                                                
  141.                                                 { Megabyte }    
  142.                                                 else if (neptunoMT > 1048576) then
  143.                                                 begin
  144.                                                         {codigo si el residuo es mayor que un gigabyte}
  145.                                                         neptunoM := neptunoMT div 1048576;
  146.                                                         neptunoMM := neptunoMT mod 1048576;
  147.                                                
  148.                                                         { Kilobyte }           
  149.                                                         if (neptunoMM >= 1024) then
  150.                                                         begin
  151.                                                                 {codigo si el residuo es mayor que un megabyte}
  152.                                                                 neptunoK := neptunoMM div 1024;
  153.                                                                 neptunoMK := neptunoMM mod 1024;
  154.                                                
  155.                                                                 { Byte }                       
  156.                                                                 if (neptunoMK < 1024) then
  157.                                                                 begin                                                  
  158.                                                                         {codigo si el residuo es mayor que un kilobyte}
  159.                                                                         neptunoB := neptunoMK;
  160.                                                                         {neptunoMB := neptunoMK mod 1024;}
  161.                                                                 end;
  162.                                                         end
  163.                                                        
  164.                                                         { Byte }                       
  165.                                                         else if (neptunoMM < 1024) then
  166.                                                         begin                                                  
  167.                                                                 {codigo si el residuo es mayor que un kilobyte}
  168.                                                                 neptunoB := neptunoMM;
  169.                                                                 {neptunoMB := neptunoMM mod 1024;}
  170.                                                         end
  171.                                                 end
  172.                                                        
  173.                                                 { Kilobyte }           
  174.                                                 else if (neptunoMT > 1024) then
  175.                                                 begin                                          
  176.                                                         {codigo si el residuo es mayor que un megabyte}
  177.                                                         neptunoK := neptunoMT div 1024;
  178.                                                         neptunoMK := neptunoMT mod 1024;
  179.                                        
  180.                                                         {  Byte }                      
  181.                                                         if (neptunoMK < 1024) then
  182.                                                         begin                                          
  183.                                                                 {codigo si el residuo es mayor que un kilobyte}
  184.                                                                 neptunoB := neptunoMK;
  185.                                                                 {neptunoMB := neptunoMK mod 1024;}
  186.                                                         end;
  187.                                                 end
  188.                                                
  189.                                                 { Byte }                       
  190.                                                 else if (neptunoMT < 1024) then
  191.                                                 begin
  192.                                                         {codigo si el residuo es mayor que un kilobyte}
  193.                                                         neptunoB := neptunoMT;
  194.                                                         {neptunoMB := neptunoMT mod 1024;}
  195.                                                 end
  196.                                         end
  197.                                                                                
  198.                                         { Gigabytes d Petabytes}
  199.                                         else if (neptunoMP > 1073741824) then
  200.                                         begin                                  
  201.                                                 {codigo si el residuo es mayor que un Gigabyte}
  202.                                                 neptunoG := neptunoMP div 1073741824;
  203.                                                 neptunoMG := neptunoMP mod 1073741824;
  204.                                            
  205.                                                 { Megabyte }    
  206.                                                 if (neptunoMG > 1048576) then
  207.                                                 begin                                  
  208.                                                         {codigo si el residuo es mayor que un Megabyte}
  209.                                                         neptunoM := neptunoMG div 1048576;
  210.                                                         neptunoMM := neptunoMG mod 1048576;
  211.                                        
  212.                                                         { Kilobyte }           
  213.                                                         if (neptunoMM >= 1024) then
  214.                                                         begin                                          
  215.                                                                 {codigo si el residuo es mayor que un Kilobyte}
  216.                                                                 neptunoK := neptunoMM div 1024;
  217.                                                                 neptunoMK := neptunoMM mod 1024;
  218.                                        
  219.                                                                 {  Byte }                      
  220.                                                                 if (neptunoMK < 1024) then
  221.                                                                 begin                                                  
  222.                                                                         {codigo si el residuo es mayor que un Byte}
  223.                                                                         neptunoB := neptunoMK;
  224.                                                                         {neptunoMB := neptunoMK mod 1024;}
  225.                                                                 end;
  226.                                                         end
  227.                                                        
  228.                                                         {  Byte }                      
  229.                                                         else if (neptunoMM < 1024) then
  230.                                                         begin
  231.                                                                 {codigo si el residuo es mayor que un kilobyte}
  232.                                                                 neptunoB := neptunoMM;
  233.                                                                 {neptunoMB := neptunoMM mod 1024;}
  234.                                                         end;
  235.                                                 end
  236.  
  237.                                                 { Kilobyte }           
  238.                                                 else if (neptunoMG >= 1024) then
  239.                                                 begin                                          
  240.                                                         {codigo si el residuo es mayor que un megabyte}
  241.                                                         neptunoK := neptunoMG div 1024;
  242.                                                         neptunoMK := neptunoMG mod 1024;
  243.                                        
  244.                                                         {  Byte }                      
  245.                                                         if (neptunoMK < 1024) then
  246.                                                         begin                                          
  247.                                                                 {codigo si el residuo es mayor que un kilobyte}
  248.                                                                 neptunoB := neptunoMK;
  249.                                                                 {neptunoMB := neptunoMK mod 1024;}
  250.                                                         end;
  251.                                                 end
  252.                                                
  253.                                                 { Byte }                       
  254.                                                 else if (neptunoMG < 1024) then
  255.                                                 begin
  256.                                                         {codigo si el residuo es mayor que un kilobyte}
  257.                                                         neptunoB := neptunoMG;
  258.                                                         {neptunoMB := neptunoMG mod 1024;}
  259.                                                 end;
  260.                                         end
  261.                                        
  262.                                         { Megabyte d Petabytes }    
  263.                                         else if (neptunoMP > 1048576) then
  264.                                         begin                                  
  265.                                                 {codigo si el residuo es mayor que un gigabyte}
  266.                                                 neptunoM := neptunoMP div 1048576;
  267.                                                 neptunoMM := neptunoMP mod 1048576;
  268.                                        
  269.                                                 { Kilobyte }           
  270.                                                 if (neptunoMM >= 1024) then
  271.                                                 begin
  272.                                                         {codigo si el residuo es mayor que un megabyte}
  273.                                                         neptunoK := neptunoMM div 1024;
  274.                                                         neptunoMK := neptunoMM mod 1024;
  275.                        
  276.                                                         {  Byte }                      
  277.                                                         if (neptunoMK < 1024) then
  278.                                                         begin                                          
  279.                                                                 {codigo si el residuo es mayor que un kilobyte}
  280.                                                                 neptunoB := neptunoMK;
  281.                                                                 {neptunoMB := neptunoMK mod 1024;}
  282.                                                         end;
  283.                                                 end
  284.                                                
  285.                                                 {  Byte }                      
  286.                                                 else if (neptunoMM < 1024) then
  287.                                                 begin                                          
  288.                                                         {codigo si el residuo es mayor que un kilobyte}
  289.                                                         neptunoB := neptunoMM;
  290.                                                         {neptunoMB := neptunoMM mod 1024;}
  291.                                                 end;
  292.                                         end
  293.                                                
  294.                                         { Kilobyte d Petabytes}        
  295.                                         else if (neptunoMP > 1024) then
  296.                                         begin
  297.                                                 {codigo si el residuo es mayor que un megabyte}
  298.                                                 neptunoK := neptunoMP div 1024;
  299.                                                 neptunoMK := neptunoMP mod 1024;
  300.                                
  301.                                                 { Byte }                       
  302.                                                 if (neptunoMK < 1024) then
  303.                                                 begin
  304.                                                         neptunoB := neptunoMK;
  305.                                                 end;
  306.                                         end
  307.                                        
  308.                                         { Byte d Petabytes }                   
  309.                                         else if (neptunoMP < 1024) then
  310.                                         begin
  311.                                                 {codigo si el residuo es menor que un kilobyte}
  312.                                                 neptunoB := neptunoMP
  313.                                                 {neptunoMB := neptunoMP mod 1024;}
  314.                                         end;
  315.                                 end
  316.  
  317.                                 else if (mercurio <1) then
  318.                                 begin
  319.                                         writeln('Ha digitado la cantidad de ',mercurio,' bytes, para un numero exacto de ',neptunoP,' Petabytes')
  320.                                 end;
  321.                         end
  322.  
  323.         { /*************************************************************************/ }
  324.  
  325.         { aqui termina el universo de terabyte y comienza el surgimiento del reino de Terabyte }
  326.  
  327.         { /*************************************************************************/ }
  328.                                 { Terabyte Root }
  329.         { /*************************************************************************/ }
  330.  
  331.                         else if (mercurio >= 1099511627776) then
  332.                         begin
  333.                                 neptunoT := mercurio div 1099511627776;
  334.                                 neptunoMT := mercurio mod 1099511627776;                              
  335.  
  336.                                 { Solo para verificar que no se ingreso una cantidad exacta de Terabytes }
  337.                                 if (neptunoMT > 0) then
  338.                                 begin
  339.                
  340.                                         { Gigabyte }
  341.                                         if (neptunoMT > 1073741824) then
  342.                                         begin
  343.                                                 {codigo si el residuo es mayor que un terabyte}
  344.                                                 neptunoG := neptunoMT div 1073741824;
  345.                                                 neptunoMG := neptunoMT mod 1073741824;
  346.                                            
  347.                                                 { Megabyte }    
  348.                                                 if (neptunoMG > 1048576) then
  349.                                                 begin
  350.                                                         {codigo si el residuo es mayor que un gigabyte}
  351.                                                         neptunoM := neptunoMG div 1048576;
  352.                                                         neptunoMM := neptunoMG mod 1048576;
  353.                                        
  354.                                                         { Kilobyte }           
  355.                                                         if (neptunoMM >= 1024) then
  356.                                                         begin
  357.                                                                 {codigo si el residuo es mayor que un megabyte}
  358.                                                                 neptunoK := neptunoMM div 1024;
  359.                                                                 neptunoMK := neptunoMM mod 1024;
  360.                                                
  361.                                                                 {  Byte }                      
  362.                                                                 if (neptunoMK < 1024) then
  363.                                                                 begin
  364.                                                                         {codigo si el residuo es mayor que un kilobyte}
  365.                                                                         neptunoB := neptunoMK;
  366.                                                                         {neptunoMB := neptunoMK mod 1024;}
  367.                                                                 end;
  368.                                                         end
  369.                                                        
  370.                                                         { Byte }                       
  371.                                                         else if (neptunoMM < 1024) then
  372.                                                         begin
  373.                                                                 {codigo si el residuo es mayor que un kilobyte}
  374.                                                                 neptunoB := neptunoMM;
  375.                                                                 {neptunoMB := neptunoMM mod 1024;}
  376.                                                         end;
  377.                                                 end
  378.  
  379.                                                 { Kilobyte }           
  380.                                                 else if (neptunoMG >= 1024) then
  381.                                                 begin
  382.                                                         {codigo si el residuo es mayor que un megabyte}
  383.                                                         neptunoK := neptunoMG div 1024;
  384.                                                         neptunoMK := neptunoMG mod 1024;
  385.                                                        
  386.                                                         {  Byte }                      
  387.                                                         if (neptunoMK < 1024) then
  388.                                                         begin
  389.                                                                 {codigo si el residuo es mayor que un kilobyte}
  390.                                                                 neptunoB := neptunoMK;
  391.                                                                 {neptunoMB := neptunoMK mod 1024;}
  392.                                                         end;
  393.                                                 end
  394.                                                
  395.                                                 {  Byte }                      
  396.                                                 else if (neptunoMG < 1024) then
  397.                                                 begin                          
  398.                                                         {codigo si el residuo es mayor que un kilobyte}
  399.                                                         neptunoB := neptunoMG;
  400.                                                         {neptunoMB := neptunoMG mod 1024;}
  401.                                                 end;
  402.                                         end
  403.                                        
  404.                                         { Megabyte }    
  405.                                         else if (neptunoMT > 1048576) then
  406.                                         begin
  407.                                                 {codigo si el residuo es mayor que un gigabyte}
  408.                                                 neptunoM := neptunoMT div 1048576;
  409.                                                 neptunoMM := neptunoMT mod 1048576;
  410.                                        
  411.                                                 { Kilobyte }           
  412.                                                 if (neptunoMM >= 1024) then
  413.                                                 begin
  414.                                                         {codigo si el residuo es mayor que un megabyte}
  415.                                                         neptunoK := neptunoMM div 1024;
  416.                                                         neptunoMK := neptunoMM mod 1024;
  417.                                                
  418.                                                         { Byte }                       
  419.                                                         if (neptunoMK < 1024) then
  420.                                                         begin
  421.                                                                 {codigo si el residuo es mayor que un kilobyte}
  422.                                                                 neptunoB := neptunoMK;
  423.                                                                 {neptunoMB := neptunoMK mod 1024;}
  424.                                                         end;
  425.                                                 end
  426.                                                
  427.                                                 {  Byte }                      
  428.                                                 else if (neptunoMM < 1024) then
  429.                                                 begin
  430.                                                         {codigo si el residuo es mayor que un kilobyte}
  431.                                                         neptunoB := neptunoMM;
  432.                                                         {neptunoMB := neptunoMM mod 1024;}
  433.                                                 end;
  434.                                         end
  435.                                                                
  436.                                         { Kilobyte }           
  437.                                         else if (neptunoMT > 1024) then
  438.                                         begin
  439.                                                 {codigo si el residuo es mayor que un megabyte}
  440.                                                 neptunoK := neptunoMT div 1024;
  441.                                                 neptunoMK := neptunoMT mod 1024;
  442.                                
  443.                                                 {  Byte }                      
  444.                                                 if (neptunoMK < 1024) then
  445.                                                 begin
  446.                                                         {codigo si el residuo es mayor que un kilobyte}
  447.                                                         neptunoB := neptunoMK;
  448.                                                         {neptunoMB := neptunoMK mod 1024;}
  449.                                                 end;
  450.                                         end
  451.                                        
  452.                                         { Byte }                       
  453.                                         else if (neptunoMT < 1024) then
  454.                                         begin
  455.                                                 {codigo si el residuo es mayor que un kilobyte}
  456.                                                 neptunoB := neptunoMT;
  457.                                                 {neptunoMB := neptunoMT mod 1024;}
  458.                                         end;
  459.                                 end
  460.                                 else
  461.                                 begin
  462.                                         writeln('Ha digitado la cantidad de ',mercurio,' bytes, para un numero exacto de ',neptunoT,' Terabytes');
  463.                                 end;
  464.                         end
  465.  
  466.         { /*************************************************************************/ }
  467.                                 { Gigabytes Root }
  468.         { /*************************************************************************/ }
  469.  
  470.                         else if (mercurio > 1073741824) then
  471.                         begin
  472.                                 {codigo si el residuo es mayor que un terabyte}
  473.                                 neptunoG := mercurio div 1073741824;
  474.                                 neptunoMG := mercurio mod 1073741824;
  475.  
  476.                                 { Solo para verificar que no se ingreso una cantidad exacta de Gigabytes }
  477.                                 if (neptunoMG > 0) then                            
  478.                                 begin
  479.                                         { Megabyte }    
  480.                                         if (neptunoMG > 1048576) then
  481.                                         begin
  482.                                                 {codigo si el residuo es mayor que un gigabyte}
  483.                                                 neptunoM := neptunoMG div 1048576;
  484.                                                 neptunoMM := neptunoMG mod 1048576;
  485.                                
  486.                                                 { Kilobyte }           
  487.                                                 if (neptunoMM >= 1024) then
  488.                                                 begin
  489.                                                         {codigo si el residuo es mayor que un megabyte}
  490.                                                         neptunoK := neptunoMM div 1024;
  491.                                                         neptunoMK := neptunoMM mod 1024;
  492.                                
  493.                                                         {  Byte }                      
  494.                                                         if (neptunoMK < 1024) then
  495.                                                         begin
  496.                                                                 {codigo si el residuo es mayor que un kilobyte}
  497.                                                                 neptunoB := neptunoMK;
  498.                                                                 {neptunoMB := neptunoMK mod 1024;}
  499.                                                         end;
  500.                                                 end
  501.  
  502.                                                 { Byte }                       
  503.                                                 else if (neptunoMM < 1024) then
  504.                                                 begin
  505.                                                         {codigo si el residuo es mayor que un kilobyte}
  506.                                                         neptunoB := neptunoMM;
  507.                                                         {neptunoMB := neptunoMM mod 1024;}
  508.                                                 end;
  509.                                         end
  510.  
  511.                                         { Kilobyte }           
  512.                                         else if (neptunoMG >= 1024) then
  513.                                         begin
  514.                                                 {codigo si el residuo es mayor que un megabyte}
  515.                                                 neptunoK := neptunoMG div 1024;
  516.                                                 neptunoMK := neptunoMG mod 1024;
  517.                                
  518.                                                 {  Byte }                      
  519.                                                 if (neptunoMK < 1024) then
  520.                                                 begin
  521.                                                         {codigo si el residuo es mayor que un kilobyte}
  522.                                                         neptunoB := neptunoMK;
  523.                                                         {neptunoMB := neptunoMK mod 1024;}
  524.                                                 end;
  525.                                         end
  526.                                        
  527.                                         {  Byte }                      
  528.                                         else if (neptunoMG < 1024) then
  529.                                         begin
  530.                                                 {codigo si el residuo es mayor que un kilobyte}
  531.                                                 neptunoB := neptunoMG;
  532.                                                 {neptunoMB := neptunoMG mod 1024;}
  533.                                         end;
  534.                                 end
  535.                                 else
  536.                                 begin
  537.                                         writeln('Ha digitado la cantidad de ',mercurio,' bytes, para un numero exacto de ',neptunoT,' gIGAbytes');
  538.                                 end;
  539.                         end
  540.  
  541.         { /*************************************************************************/ }
  542.                                 { Megabyte Root }    
  543.         { /*************************************************************************/ }
  544.  
  545.                         else if (mercurio > 1048576) then
  546.                         begin
  547.                                 {codigo si el residuo es mayor que un gigabyte}
  548.                                 neptunoM := mercurio div 1048576;
  549.                                 neptunoMM := mercurio mod 1048576;
  550.                                
  551.                                 { Solo para verificar que no se ingreso una cantidad exacta de petabytes }
  552.                                 if (neptunoMP > 0) then
  553.                                 begin
  554.                                         { Kilobyte }           
  555.                                         if (neptunoMM >= 1024) then
  556.                                         begin
  557.                                                 {codigo si el residuo es mayor que un megabyte}
  558.                                                 neptunoK := neptunoMM div 1024;
  559.                                                 neptunoMK := neptunoMM mod 1024;
  560.                
  561.                                                 {  Byte }                      
  562.                                                 if (neptunoMK < 1024) then
  563.                                                 begin
  564.                                                         {codigo si el residuo es mayor que un kilobyte}
  565.                                                         neptunoB := neptunoMK;
  566.                                                         {neptunoMB := neptunoMK mod 1024;}
  567.                                                 end;
  568.                                         end
  569.                                        
  570.                                         { Byte }                       
  571.                                         else if (neptunoMM < 1024) then
  572.                                         begin
  573.                                                 {codigo si el residuo es mayor que un kilobyte}
  574.                                                 neptunoB := neptunoMM;
  575.                                                 {neptunoMB := neptunoMM mod 1024;}
  576.                                         end;
  577.                                 end
  578.                                 else
  579.                                 begin
  580.                                         writeln('Ha digitado la cantidad de ',mercurio,' bytes, para un numero exacto de ',neptunoT,' Gigabytes');
  581.                                 end;
  582.                         end
  583.  
  584.         { /*************************************************************************/ }                                
  585.                         { Kilobyte Root }
  586.         { /*************************************************************************/ }
  587.                
  588.                         else if (mercurio >= 1024) then
  589.                         begin
  590.                                 {codigo si el residuo es mayor que un megabyte}
  591.                                 neptunoK := mercurio div 1024;
  592.                                 neptunoMK := mercurio mod 1024;
  593.                
  594.                                 {  Byte }                      
  595.                                 if (neptunoMK < 1024) then
  596.                                 begin
  597.                                         {codigo si el residuo es mayor que un kilobyte}
  598.                                         neptunoB := neptunoMK;
  599.                                         {neptunoMB := neptunoMK mod 1024;}
  600.                                 end;
  601.                         end
  602.                
  603.         { /*************************************************************************/ }
  604.                         { Byte Root }                  
  605.         { /*************************************************************************/ }
  606.  
  607.                         else if (mercurio < 1024) then
  608.                         begin
  609.                                 {codigo si el residuo es mayor que un kilobyte}
  610.                                 neptunoB := mercurio;
  611.                                 {neptunoMB := mercurio mod 1024;}
  612.                         end
  613.                 {/*******************************************************/}
  614.  
  615.  
  616.                         { Rara ocasion en la que ingresen una cantidad exacta de bytes de un petabyte }
  617.                         else
  618.                         begin
  619.                                 writeln('La conversion de ',mercurio,' bytes es: ',neptunoP,' petabytes exactos.');    
  620.                         end;
  621.                 end;
  622.                
  623.                 'e' : begin
  624.                         writeln('Hasta luego!')
  625.                 end;
  626.         end;
  627.  
  628.         writeln('END_OF_FILE__');
  629. end.
  630.  


I realized that when I compile exactly the same code, in archlinux without specifying the target system compiles it and returns the executable while in CentOs specifying the target system (by default since I do not remember moving anything to the configuration) it returns an error and does not generate the executable.

Title: Re: i don't know why
Post by: BlueIcaro on May 20, 2018, 10:55:39 pm
Did you try to use procedures and/or functions?.
Your code will more easy to read and understand.
For example, in case 'C' entry yoy have a long code. Put in a procedure, as I said will be more easy to read, understand and debug.

/BlueIcaro
Title: Re: i don't know why
Post by: NightWing on May 21, 2018, 12:33:08 am
Did you try to use procedures and/or functions?.
Your code will more easy to read and understand.
For example, in case 'C' entry yoy have a long code. Put in a procedure, as I said will be more easy to read, understand and debug.

/BlueIcaro

Of course, but I was looking to learn how to nest several if-else-if & the general use of the ' ; ' . Since its use is different than other languages i.e. 'C' or 'Matlab'.
I'm new to pascal but not in programming.

You do not learn to run before you walk.. ¿right?  8-)
Title: Re: A lot If-Else-If
Post by: NightWing on May 31, 2018, 03:35:39 am
This code works, not as the syntax says it works but it works.

Thanks for the help

P.S.  I exceeded the character limit, that's why I post it in document
P.S2. I say bits no bytes
Title: Re: A lot If-Else-If
Post by: Handoko on May 31, 2018, 05:06:32 am
I tested the code, it compiles and runs. It seems you now already understand how to use nested if-then-else. So, if you want to improve your skill further you should re-read the posts from the beginning. All of their advices are true, the most notable problem is, you're doing a simple thing using a not simple solution. It makes the code harder to maintain and prone to bugs.

For your information, this is how to attach code to the forum:
Copy all the files into a new folder, except: the binary, *.exe, *.bak and the lib folder. Compress that folder and send the zip file to the forum.

And these are my recommend reading materials for beginners:

Lazarus tutorial for beginners:
http://wiki.lazarus.freepascal.org/Lazarus_Tutorial

List of tutorials with wide range of topics (graphics, database, printer, web, etc):
http://wiki.freepascal.org/Lazarus_Documentation#Lazarus.2FFPC_.28Free_Pascal.29
http://wiki.freepascal.org/Category:Tutorials

(Free) Pascal reference guide:
http://freepascal.org/docs-html/current/ref/ref.html

If you're looking for step-by-step Pascal tutorial, try these: http://www.pascal-programming.info/index.php
http://www.taoyue.com/tutorials/pascal/index.html

Some cool Pascal tricks:
http://lazplanet.blogspot.co.id/

Pascal video tutorials:
https://devstructor.com/index.php?page=tutorials

Lazarus IDE tricks (some are with animation):
http://wiki.freepascal.org/New_IDE_features_since
Title: Re: A lot If-Else-If
Post by: Ñuño_Martínez on May 31, 2018, 10:52:03 am
Ok, you fixed it, but I have an advise to make:

It is not a good idea to write so much code inside a CASE.  Instead you should create several PROCEDUREs or FUNCTIONs to do the work and call them from the CASE.  That will make things easier to read and you'll avoid this problem in the future.
Title: Re: A lot If-Else-If
Post by: Thaddy on May 31, 2018, 11:20:38 am
Well, correct, but the existing code can also be simplified by using ranges in the case statements.
Example:
Code: Pascal  [Select][+][-]
  1. {$mode objfpc}{$J+}
  2. var
  3.   neptunoMP:qword = 1125899906842627;
  4. begin
  5.   // if (neptunoMP >= 1099511627776) and (neptunoMP < 1125899906842624) then
  6.   case neptunoMP of
  7.   1099511627776..1125899906842624:; // range
  8.   // etc
  9.   end;
  10. end.

If you do that everywhere the code becomes much more readable without all the ifs.
This is a feature of case blocks that many programmers forget about.
TinyPortal © 2005-2018