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.