my code can't seem to find the maximum price.

program Mobile;
uses winCrt;
type
    Mobilephone=record
          brand:integer;
          model:String;
          price:real;
    end;

var
    hp:array[1..100] of Mobilephone;
    count,m,MobileNum:integer;
    max:real;

PROCEDURE read_data(var newMobile:Mobilephone);
begin
writeln('Brand:(1:Samsung 2:iPhone 3:Nokia)');
readln(newMobile.brand);
writeln('Model:');
readln(newMobile.model);
writeln('Price:');
readln(newMobile.price);

end;

PROCEDURE displayexp(var exp:Mobilephone);
begin
if(exp.price>max) then
begin
writeln('THE MOST EXPENSIVE HP:');
writeln('Brand: ',exp.brand);
writeln('Model: ',exp.model);
writeln('Price: ',exp.price:5:2);
end;
end;

PROCEDURE displaySamsung(var sam:Mobilephone);
begin
if(sam.brand=1)  then
begin
writeln('Samsung models: ',sam.model);
writeln('Total number: ',count);
end;
end;


Begin

writeln('Enter number of mobile phones: ');
readln(MobileNum);
    writeln;

    For m := 1 to MobileNum do
    begin
        read_data(hp[m]);
        writeln;
        if(hp[m].brand=1) then
        begin
        count:=count+1;
        end;


     end;

        displayexp(hp[m]);
        writeln;


     writeln('SAMSUNG:');
     for m:=1 to MobileNum do
     begin
     displaySamsung(hp[m]);
     end;

     delay(10000);

end.

Then use a procedure "DisplayMaxPrice" or something like that.
In the procedure, start with a MaxPrice := -1.0;
Iterate through all your records change MaxPrice to the price of a cellphone if it is greater than the current MaxPrice.
Display MaxPrice, which after the end of the loop now must contain the maximum price.
Success!

Edited 3 Years Ago by ddanbe: typo

This article has been dead for over six months. Start a new discussion instead.