Forum > Beginners

A lot If-Else-If

(1/6) > >>

NightWing:
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)

Kays:

--- Quote from: NightWing on May 08, 2018, 12:03:40 am ---[…] i got this code […]
--- End quote ---
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.

Josh:
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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program puff;uses crt;var        mercurio, tierra, marte, jupiter, saturno, urano, neptuno, neptunoB, neptunoK, neptunoM, neptunoG, neptunoT, neptunoP, neptunoMB, neptunoMK, neptunoMM, neptunoMG, neptunoMT, neptunoMP, pluton : int64;        venus : string; { o char}begin  clrscr;  writeln('Hello there!');  writeln('Ingrese la cantidad de bytes a convertir: ');  readln(mercurio);   writeln('');  writeln('¿A que unidad los quiere convertir?');  writeln(' k = kilobytes, m = megabytes, g = gigabytes, t = terabytes');  writeln(' p = petabytes, c = exacto / -v, e = salir ');  readln(venus);   case venus of     { Convertir a kilobytes }     'k' : begin            tierra := mercurio div 1024;            {pluton := tierra mod 1024;}            writeln('El resultado de convertir ',mercurio,' bytes a kilobytes es: ',tierra,'.');          end;     { Convertir a megabytes }     'm' : begin            marte := mercurio div 1048576;            {pluton := tierra mod 1024;}            writeln('El resultado de convertir ',mercurio,' bytes a megabytes es: ',marte,'.');          end;     { Convertir a gigabytes }     'g' : begin            jupiter := mercurio div 1073741824;            {pluton := tierra mod 1024;}            writeln('El resultado de convertir ',mercurio,' bytes a megabytes es: ',jupiter,'.');          end;     { Convertir a terabytes }     't' : begin            saturno := mercurio div 1099511627776;            {pluton := tierra mod 1024;}            writeln('El resultado de convertir ',mercurio,' bytes a terabytes es: ',saturno,'.');          end;     { Convertir a petabytes }     'p' : begin            urano := mercurio div 1125899906842624;            {pluton := tierra mod 1024;}            writeln('El resultado de convertir ',mercurio,' bytes a petabytes es: ',urano,'.');          end;     { Conversion exacta / -v }     'c' : begin             { /*************************************************************************/ }                                { Petabytes Root }            { /*************************************************************************/ }             if (mercurio >= 1125899906842624) then            begin              neptunoP := mercurio div 1125899906842624;              neptunoMP := mercurio mod 1125899906842624;               { Solo para verificar que no se ingreso una cantidad exacta de petabytes }              if (neptunoMP > 0) then              begin                { Terabyte }                if (neptunoMP >= 1099511627776) and (neptunoMP < 1125899906842624) then                begin                  neptunoT := neptunoMP div 1099511627776;                  neptunoMT := neptunoMP mod 1099511627776;                   { Gigabyte }                  if (neptunoMT >= 1073741824) then                  begin                    { codigo si el residuo es mayor que un terabyte }                    neptunoG := neptunoMT div 1073741824;               { 1073741024: Valor minimo para ser considerado terabytes }                    neptunoMG := neptunoMT mod 1073741824;                      { falta formula para saber si no es un terabyte exacto }                    { if MG > 0 then .. && empieza la formula siguiente de megabytes }                     { Megabyte }                    if (neptunoMG > 1048576) then                    begin                      {codigo si el residuo es mayor que un gigabyte}                      neptunoM := neptunoMG div 1048576;                      neptunoMM := neptunoMG mod 1048576;                       { Kilobyte }                      if (neptunoMM >= 1024) then                      begin                        {codigo si el residuo es mayor que un megabyte}                        neptunoK := neptunoMM div 1024;                        neptunoMK := neptunoMM mod 1024;                         {  Byte }                        if (neptunoMK < 1024) then                        begin                          {codigo si el residuo es mayor que un kilobyte}                          neptunoB := neptunoMK;                           {neptunoMB := neptunoMK mod 1024;}                        end;                      end                       { Byte }                      else if (neptunoMM < 1024) then                      begin                        {codigo si el residuo es mayor que un kilobyte}                        neptunoB := neptunoMM;                        {neptunoMB := neptunoMM mod 1024;}                      End                    end                     { Kilobyte }                     else if (neptunoMG >= 1024) then                    begin                      {codigo si el residuo es mayor que un megabyte}                      neptunoK := neptunoMG div 1024;                      neptunoMK := neptunoMG mod 1024;                       { Byte }                       if (neptunoMK < 1024) then                      begin                        {codigo si el residuo es mayor que un kilobyte}                        neptunoB := neptunoMK;                      End;                    end                     { Byte }                    else if (neptunoMG < 1024) then                    begin                      neptunoB := neptunoMG;                    end                        end                   { Megabyte }                  else if (neptunoMT > 1048576) then                  begin                    {codigo si el residuo es mayor que un gigabyte}                    neptunoM := neptunoMT div 1048576;                    neptunoMM := neptunoMT mod 1048576;                     { Kilobyte }                    if (neptunoMM >= 1024) then                    begin                      {codigo si el residuo es mayor que un megabyte}                      neptunoK := neptunoMM div 1024;                      neptunoMK := neptunoMM mod 1024;                       { Byte }                      if (neptunoMK < 1024) then                      begin                        {codigo si el residuo es mayor que un kilobyte}                        neptunoB := neptunoMK;                        {neptunoMB := neptunoMK mod 1024;}                      End;                    end                     { Byte }                    else if (neptunoMM < 1024) then                    begin                      {codigo si el residuo es mayor que un kilobyte}                      neptunoB := neptunoMM;                      {neptunoMB := neptunoMM mod 1024;}                    end                  end                   { Kilobyte }                  else if (neptunoMT > 1024) then                  begin                    {codigo si el residuo es mayor que un megabyte}                    neptunoK := neptunoMT div 1024;                    neptunoMK := neptunoMT mod 1024;                     {  Byte }                    if (neptunoMK < 1024) then                    begin                      {codigo si el residuo es mayor que un kilobyte}                      neptunoB := neptunoMK;                      {neptunoMB := neptunoMK mod 1024;}                    end;                  end                   { Byte }                  else if (neptunoMT < 1024) then                  begin                    {codigo si el residuo es mayor que un kilobyte}                    neptunoB := neptunoMT;                    {neptunoMB := neptunoMT mod 1024;}                  end                end                 { Gigabytes d Petabytes}                else if (neptunoMP > 1073741824) then                begin                  {codigo si el residuo es mayor que un Gigabyte}                  neptunoG := neptunoMP div 1073741824;                  neptunoMG := neptunoMP mod 1073741824;                   { Megabyte }                  if (neptunoMG > 1048576) then                  begin                    {codigo si el residuo es mayor que un Megabyte}                    neptunoM := neptunoMG div 1048576;                    neptunoMM := neptunoMG mod 1048576;                     { Kilobyte }                    if (neptunoMM >= 1024) then                    begin                      {codigo si el residuo es mayor que un Kilobyte}                      neptunoK := neptunoMM div 1024;                      neptunoMK := neptunoMM mod 1024;                       {  Byte }                      if (neptunoMK < 1024) then                      begin                        {codigo si el residuo es mayor que un Byte}                        neptunoB := neptunoMK;                        {neptunoMB := neptunoMK mod 1024;}                      end;                    end                     {  Byte }                    else if (neptunoMM < 1024) then                    {codigo si el residuo es mayor que un kilobyte}                    neptunoB := neptunoMM;                    {neptunoMB := neptunoMM mod 1024;}                  end                end                 { Kilobyte }                else if (neptunoMG >= 1024) then                begin                  {codigo si el residuo es mayor que un megabyte}                  neptunoK := neptunoMG div 1024;                  neptunoMK := neptunoMG mod 1024;                   {  Byte }                  if (neptunoMK < 1024) then                  begin                    {codigo si el residuo es mayor que un kilobyte}                    neptunoB := neptunoMK;                    {neptunoMB := neptunoMK mod 1024;}                  end;                end                 { Byte }                else if (neptunoMG < 1024) then                  {codigo si el residuo es mayor que un kilobyte}                  neptunoB := neptunoMG;                  {neptunoMB := neptunoMG mod 1024;}              end            end             { Megabyte d Petabytes }            else if (neptunoMP > 1048576) then            begin              {codigo si el residuo es mayor que un gigabyte}              neptunoM := neptunoMP div 1048576;              neptunoMM := neptunoMP mod 1048576;               { Kilobyte }              if (neptunoMM >= 1024) then              begin                {codigo si el residuo es mayor que un megabyte}                neptunoK := neptunoMM div 1024;                neptunoMK := neptunoMM mod 1024;                 {  Byte }                if (neptunoMK < 1024) then                begin                  {codigo si el residuo es mayor que un kilobyte}                  neptunoB := neptunoMK;                  {neptunoMB := neptunoMK mod 1024;}                end;              end               {  Byte }              else if (neptunoMM < 1024) then                {codigo si el residuo es mayor que un kilobyte}                neptunoB := neptunoMM;                {neptunoMB := neptunoMM mod 1024;}            end    end        // end of case c     { Kilobyte d Petabytes}    else if (neptunoMP > 1024) then    begin      {codigo si el residuo es mayor que un megabyte}      neptunoK := neptunoMP div 1024;      neptunoMK := neptunoMP mod 1024;       { Byte }      if (neptunoMK < 1024) then      begin        neptunoB := neptunoMK;      End;    end     { Byte d Petabytes }    else if (neptunoMP < 1024) then    begin      {codigo si el residuo es menor que un kilobyte}      neptunoB := neptunoMP      {neptunoMB := neptunoMP mod 1024;}    end  end       // end of case statment   else if (mercurio <1) then    writeln('Ha digitado la cantidad de ',mercurio,' bytes, para un numero exacto de ',neptunoP,' Petabytes');end     // run out of indentation something wrong         { /*************************************************************************/ }         { aqui termina el universo de terabyte y comienza el surgimiento del reino de Terabyte }         { /*************************************************************************/ }                                { Terabyte Root }        { /*************************************************************************/ }                         else if (mercurio >= 1099511627776) then                        begin                                neptunoT := mercurio div 1099511627776;                                neptunoMT := mercurio mod 1099511627776;                                 { Solo para verificar que no se ingreso una cantidad exacta de Terabytes }                                if (neptunoMT > 0) then                                begin                                         { Gigabyte }                                        if (neptunoMT > 1073741824) then                                        begin                                                {codigo si el residuo es mayor que un terabyte}                                                neptunoG := neptunoMT div 1073741824;                                                neptunoMG := neptunoMT mod 1073741824;                                                 { Megabyte }                                                if (neptunoMG > 1048576) then                                                begin                                                        {codigo si el residuo es mayor que un gigabyte}                                                        neptunoM := neptunoMG div 1048576;                                                        neptunoMM := neptunoMG mod 1048576;                                                         { Kilobyte }                                                        if (neptunoMM >= 1024) then                                                        begin                                                                {codigo si el residuo es mayor que un megabyte}                                                                neptunoK := neptunoMM div 1024;                                                                neptunoMK := neptunoMM mod 1024;                                                                 {  Byte }                                                                if (neptunoMK < 1024) then                                                                begin                                                                        {codigo si el residuo es mayor que un kilobyte}                                                                        neptunoB := neptunoMK;                                                                        {neptunoMB := neptunoMK mod 1024;}                                                                end;                                                        end                                                         { Byte }                                                        else if (neptunoMM < 1024) then                                                        begin                                                                {codigo si el residuo es mayor que un kilobyte}                                                                neptunoB := neptunoMM;                                                                {neptunoMB := neptunoMM mod 1024;}                                                        end;                                                end                                                 { Kilobyte }                                                else if (neptunoMG >= 1024) then                                                begin                                                        {codigo si el residuo es mayor que un megabyte}                                                        neptunoK := neptunoMG div 1024;                                                        neptunoMK := neptunoMG mod 1024;                                                         {  Byte }                                                        if (neptunoMK < 1024) then                                                        begin                                                                {codigo si el residuo es mayor que un kilobyte}                                                                neptunoB := neptunoMK;                                                                {neptunoMB := neptunoMK mod 1024;}                                                        end;                                                end                                                 {  Byte }                                                else if (neptunoMG < 1024) then                                                        {codigo si el residuo es mayor que un kilobyte}                                                        neptunoB := neptunoMG;                                                        {neptunoMB := neptunoMG mod 1024;}                                                end;                                        end                                         { Megabyte }                                        else if (neptunoMT > 1048576) then                                        begin                                                {codigo si el residuo es mayor que un gigabyte}                                                neptunoM := neptunoMT div 1048576;                                                neptunoMM := neptunoMT mod 1048576;                                                 { Kilobyte }                                                if (neptunoMM >= 1024) then                                                begin                                                        {codigo si el residuo es mayor que un megabyte}                                                        neptunoK := neptunoMM div 1024;                                                        neptunoMK := neptunoMM mod 1024;                                                         { Byte }                                                        if (neptunoMK < 1024) then                                                        begin                                                                {codigo si el residuo es mayor que un kilobyte}                                                                neptunoB := neptunoMK;                                                                {neptunoMB := neptunoMK mod 1024;}                                                        end;                                                end                                                 {  Byte }                                                else if (neptunoMM < 1024) then                                                begin                                                        {codigo si el residuo es mayor que un kilobyte}                                                        neptunoB := neptunoMM;                                                        {neptunoMB := neptunoMM mod 1024;}                                                end;                                        end                                         { Kilobyte }                                        else if (neptunoMT > 1024) then                                        begin                                                {codigo si el residuo es mayor que un megabyte}                                                neptunoK := neptunoMT div 1024;                                                neptunoMK := neptunoMT mod 1024;                                                 {  Byte }                                                if (neptunoMK < 1024) then                                                begin                                                        {codigo si el residuo es mayor que un kilobyte}                                                        neptunoB := neptunoMK;                                                        {neptunoMB := neptunoMK mod 1024;}                                                end;                                        end                                         { Byte }                                        else if (neptunoMT < 1024) then                                        begin                                                {codigo si el residuo es mayor que un kilobyte}                                                neptunoB := neptunoMT;                                                {neptunoMB := neptunoMT mod 1024;}                                        end;                                end                                else                                begin                                        writeln('Ha digitado la cantidad de ',mercurio,' bytes, para un numero exacto de ',neptunoT,' Terabytes');                                end;                        end         { /*************************************************************************/ }                                { Gigabytes Root }        { /*************************************************************************/ }                         else if (mercurio > 1073741824) then                        begin                                {codigo si el residuo es mayor que un terabyte}                                neptunoG := mercurio div 1073741824;                                neptunoMG := mercurio mod 1073741824;                                 { Solo para verificar que no se ingreso una cantidad exacta de Gigabytes }                                if (neptunoMG > 0) then                                begin                                        { Megabyte }                                        if (neptunoMG > 1048576) then                                        begin                                                {codigo si el residuo es mayor que un gigabyte}                                                neptunoM := neptunoMG div 1048576;                                                neptunoMM := neptunoMG mod 1048576;                                                 { Kilobyte }                                                if (neptunoMM >= 1024) then                                                begin                                                        {codigo si el residuo es mayor que un megabyte}                                                        neptunoK := neptunoMM div 1024;                                                        neptunoMK := neptunoMM mod 1024;                                                         {  Byte }                                                        if (neptunoMK < 1024) then                                                        begin                                                                {codigo si el residuo es mayor que un kilobyte}                                                                neptunoB := neptunoMK;                                                                {neptunoMB := neptunoMK mod 1024;}                                                        end;                                                end                                                 { Byte }                                                else if (neptunoMM < 1024) then                                                begin                                                        {codigo si el residuo es mayor que un kilobyte}                                                        neptunoB := neptunoMM;                                                        {neptunoMB := neptunoMM mod 1024;}                                                end;                                        end                                         { Kilobyte }                                        else if (neptunoMG >= 1024) then                                        begin                                                {codigo si el residuo es mayor que un megabyte}                                                neptunoK := neptunoMG div 1024;                                                neptunoMK := neptunoMG mod 1024;                                                 {  Byte }                                                if (neptunoMK < 1024) then                                                begin                                                        {codigo si el residuo es mayor que un kilobyte}                                                        neptunoB := neptunoMK;                                                        {neptunoMB := neptunoMK mod 1024;}                                                end;                                        end                                         {  Byte }                                        else if (neptunoMG < 1024) then                                        begin                                                {codigo si el residuo es mayor que un kilobyte}                                                neptunoB := neptunoMG;                                                {neptunoMB := neptunoMG mod 1024;}                                        end;                                end                                else                                begin                                        writeln('Ha digitado la cantidad de ',mercurio,' bytes, para un numero exacto de ',neptunoT,' gIGAbytes');                                end;                        end         { /*************************************************************************/ }                                { Megabyte Root }        { /*************************************************************************/ }                         else if (mercurio > 1048576) then                        begin                                {codigo si el residuo es mayor que un gigabyte}                                neptunoM := mercurio div 1048576;                                neptunoMM := mercurio mod 1048576;                                 { Solo para verificar que no se ingreso una cantidad exacta de petabytes }                                if (neptunoMP > 0) then                                begin                                        { Kilobyte }                                        if (neptunoMM >= 1024) then                                        begin                                                {codigo si el residuo es mayor que un megabyte}                                                neptunoK := neptunoMM div 1024;                                                neptunoMK := neptunoMM mod 1024;                                                 {  Byte }                                                if (neptunoMK < 1024) then                                                begin                                                        {codigo si el residuo es mayor que un kilobyte}                                                        neptunoB := neptunoMK;                                                        {neptunoMB := neptunoMK mod 1024;}                                                end;                                        end                                         { Byte }                                        else if (neptunoMM < 1024) then                                        begin                                                {codigo si el residuo es mayor que un kilobyte}                                                neptunoB := neptunoMM;                                                {neptunoMB := neptunoMM mod 1024;}                                        end;                                end                                else                                begin                                        writeln('Ha digitado la cantidad de ',mercurio,' bytes, para un numero exacto de ',neptunoT,' Gigabytes');                                end;                        end         { /*************************************************************************/ }                        { Kilobyte Root }        { /*************************************************************************/ }                         else if (mercurio >= 1024) then                        begin                                {codigo si el residuo es mayor que un megabyte}                                neptunoK := mercurio div 1024;                                neptunoMK := mercurio mod 1024;                                 {  Byte }                                if (neptunoMK < 1024) then                                begin                                        {codigo si el residuo es mayor que un kilobyte}                                        neptunoB := neptunoMK;                                        {neptunoMB := neptunoMK mod 1024;}                                end;                        end         { /*************************************************************************/ }                        { Byte Root }        { /*************************************************************************/ }                         else if (mercurio < 1024) then                        begin                                {codigo si el residuo es mayor que un kilobyte}                                neptunoB := mercurio;                                {neptunoMB := mercurio mod 1024;}                        end                {/*******************************************************/}                          { Rara ocasion en la que ingresen una cantidad exacta de bytes de un petabyte }                        else                        begin                                writeln('La conversion de ',mercurio,' bytes es: ',neptunoP,' petabytes exactos.');                        end;                end:                 'e' : begin                        writeln('Hasta luego!')                end;        end;         writeln('END_OF_FILE__');end.  

NightWing:
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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---beginif (x > y) then    begin        write ('X is bigger');        z := x+y;        if (z > x) then            begin                writeln('Z is bigger');            end        else            begin                writeln('X still bigger');            end;    endelse if (x > y) then    begin         writeln ('Y is bigger');     endelse if (x == y) then    begin         writeln ('x & y are the same');     endelse    begin        writeln('something wrong happend');    end;end. 

Handoko:
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:

Navigation

[0] Message Index

[#] Next page

Go to full version