Calculate notes in pascal, lazarus

0

After entering 6 notes, get the average of the top three.

Show the message " Approved " if the average is greater than or equal to 3.5; otherwise, show " Disapproved ".

What should I do to this code to get the average of the best three?

program Project1;

{$mode objfpc}{$H+}

uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
 cthreads,
{$ENDIF}{$ENDIF}
Classes
{ you can add units after this };
   var nota,n,suma,cuenta: integer;
promedio: real;
begin
suma:=0;
cuenta:=0;
promedio:=0;
write('Cuantas notas desea Ingresar?'); readln(n);
for cuenta:=1 to n do
begin
writeln('Ingrese la nota ',cuenta,':');
readln(nota);
suma:=suma+nota;
end
promedio:=suma/n;
writeln('El promedio de las notas ingresadas es: ',promedio:4:2);
end.
    
asked by Andrews451 06.03.2018 в 19:57
source

1 answer

1

I was looking at the code you wrote. After calculating the average you should decide if it is approved or not and you are only writing the average. To get the average of the three best grades, it would be easier to make the entry of the notes in a vector then sort them, in the case that it is ascending, the three best grades will remain in the position 6, 5 and 4. I wrote a code for pascal so you can take it into account. Basically what it does is: - Enter the notes in a vector while making the total sum of the notes entered. - Then take the average. - Sort the vector in ascending order. - Take the last three notes of the ordered vector. - Take the partial average with those values. - Shows whether it is approved or not, taking into account that the total average is greater than 3.5. - Shows the average of the three best grades.

Program Project1;
uses
    crt;
var
    Notas:array [1..6] of integer;
    PromedioT, PromedioP: real;
        Suma, i, x, auxiliar, Pausa: integer;

begin
    clrscr;
    PromedioT:=0;
    PromedioP:=0;
    i:=0;
    x:=0;
    auxiliar:=0;
    suma:=0;

    for i:=1 to 6 do
    begin
        write ('Ingrese la Nota: ');
        readln (Notas[i]);
        suma:=suma+Notas[i];
    end;

    PromedioT:= Suma/6;

    for i:=1 to 6 do
    begin
        for x:=1 to 6 do
        begin
            if (Notas[i]> Notas[x]) then
            begin
                auxiliar:=Notas[i];
                Notas[i]:=Notas[x];
                Notas[x]:=auxiliar;
            end;
        end;
    end;

    if (PromedioT>3.5) then
        begin
       writeln ('Como el promedio es mayor a 3,5 estas Aprobado');
        end
    else
    begin
        writeln ('Como el promedio es menor a 3,5 estas Desaprobado');
    end;

    PromedioP:=(Notas[6]+Notas[5]+Notas[4])/3;

    writeln('El promedio de las tres mejores: ',round(PromedioP));

end.
    
answered by 26.05.2018 / 14:45
source