Sos probleme de compilation de l'algorithme

Bonjour,
svp besoin d'aide j'ai écris un algorithme avec free pascal que voici:
var
 coeff_a, coeff_b, coeff_c, delta, solutionx1, solutionx2 : real ;
(* Instructions *)
begin
(* Saisie des variables a introduire *)
 writeln; (*saut de ligne*)
 writeln; (*saut de ligne*)
 writeln('Saisir les coefficients') ;
 writeln; (*saut de ligne*)
 writeln('coeff_a =') ;
 readln(coeff_a);
 writeln('coeff_b =') ;
 readln(coeff_b);
 writeln('coeff_c =') ;
 readln(coeff_c);
 writeln; (*saut de ligne*)
 writeln; (*saut de ligne*)
 (* Formules des variables intermidiaires et/ou de sortie *)
 delta := sqr(coeff_b) - 4 * coeff_a * coeff_c ;
 if delta < 0 then
 begin
 writeln ('Delta et negatif l''équation n''a pas de solution');
 writeln;(*saut de ligne*)
 writeln;(*saut de ligne*)
 end;
 else
 begin
 solutionx1 := (- coeff_b + sqrt(delta)) / (2 * coeff_a) ;
 solutionx2 := (- coeff_b - sqrt(delta)) / (2 * coeff_a) ;
 (* Affichages des résultats *)
 writeln('Les coefficients entrés');
 writeln;(*saut de ligne*)
 writeln('coeff_a =',coeff_a) ;
 writeln('coeff_b =',coeff_b) ;
 writeln('coeff_c =',coeff_c) ;
 writeln;(*saut de ligne*)
 writeln;(*saut de ligne*)
 writeln('Delta et les solutions xi') ;
 writeln;(*saut de ligne*)
 writeln('Delta =',delta) ;
 writeln('solutionx1 =',solutionx1) ;
 writeln('solutionx2 =',solutionx2) ;
 writeln;(*saut de ligne*)
 writeln;(*saut de ligne*)
 end;
 writeln('Press [Enter] To Quit');
 readln();
end.


mais je n'arrive pas a comprendre ca marche pas. svp solution rapide venant de vous!!!!!!!

2 réponses

  1. Modérateur
    Bonjour,
    • Il manque la première ligne :
      program NomDeTonProgramme;
    • Ligne 25/26 tu as mis
      end; else
      or le
      ;
      marque la fin d'un if sans else, donc il ne sait pas à quoi sert le else... Il faut enlever ce point-virgule.
    0
    1. Modérateur
      Ceci est déjà mieux, mais il y a plein d'améliorations à effectuer. Voir commentaires.
      var
      coeff_a, coeff_b, coeff_c, delta, solutionx1, solutionx2 : real ;
      (* Instructions *)
      begin
         (* Saisie des variables a introduire *)
         writeln; (*saut de ligne*)
         writeln; (*saut de ligne*)
         writeln('Saisir les coefficients') ;
         writeln; (*saut de ligne*)
         writeln('coeff_a =') ;
         readln(coeff_a);
         writeln('coeff_b =') ;
         readln(coeff_b);
         writeln('coeff_c =') ;
         readln(coeff_c);
      
         (*il faudra tester si a =0 ou (a = 0 et b =0).....*)
         
         writeln; (*saut de ligne*)
         writeln; (*saut de ligne*)
         (* Formules des variables intermidiaires et/ou de sortie *)
         delta := coeff_b * coeff_b - 4 * coeff_a * coeff_c ;
         writeln("delta= ", delta);   
         if delta < 0 then
         begin
            writeln ('Delta et négatif l''équation n''a pas de solution');
            writeln;(*saut de ligne*)
            writeln;(*saut de ligne*)
         end
      else
      
         (* il faudra tester si delta = 0 *)
      
      begin
         writeln("HERE");
         solutionx1 := (- coeff_b + sqrt(delta)) / (2 * coeff_a) ;
         solutionx2 := (- coeff_b - sqrt(delta)) / (2 * coeff_a) ;
         (* Affichages des résultats *)
         writeln('Les coefficients entrés');
         writeln;(*saut de ligne*)
         writeln('coeff_a =',coeff_a) ;
         writeln('coeff_b =',coeff_b) ;
         writeln('coeff_c =',coeff_c) ;
         writeln;(*saut de ligne*)
         writeln;(*saut de ligne*)
         writeln('Delta et les solutions xi') ;
         writeln;(*saut de ligne*)
         writeln('Delta =',delta) ;
         writeln('solutionx1 =',solutionx1) ;
         writeln('solutionx2 =',solutionx2) ;
         writeln;(*saut de ligne*)
         writeln;(*saut de ligne*)
      end;
      end.


      Avec p2c sous linux:
      johand@bata:~/src/CCM/PASCAL$ p2cc -lm  -osecond second.pas 
      second..c:9:1: warning: return type defaults to ‘int’ [-Wimplicit-int]
      main(int argc, Char *argv[])
      ^
      johand@bata:~/src/CCM/PASCAL$ echo -e "1\n2\n-8" | ./second

      Saisir les coefficients

      coeff_a =
      coeff_b =
      coeff_c =

      delta= 3.60000E+01
      HERE
      Les coefficients entrés

      coeff_a = 1.00000E+00
      coeff_b = 2.00000E+00
      coeff_c =-8.00000E+00

      Delta et les solutions xi

      Delta = 3.60000E+01
      solutionx1 = 2.00000E+00
      solutionx2 =-4.00000E+00


      0