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.

Recommended Answers

All 3 Replies

In my observation, you have no function which remotely attempts to search for price data.

but I'm required to use procedure only.

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!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.