1,105,399 Community Members

find max price

Member Avatar
nadiah.izzati
Newbie Poster
3 posts since Jul 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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.
Member Avatar
Unimportant
Posting Whiz in Training
267 posts since Oct 2010
Reputation Points: 18 [?]
Q&As Helped to Solve: 54 [?]
Skill Endorsements: 9 [?]
 
0
 

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

Member Avatar
nadiah.izzati
Newbie Poster
3 posts since Jul 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

but I'm required to use procedure only.

Member Avatar
ddanbe
Posting Expert
5,339 posts since Oct 2008
Reputation Points: 2,054 [?]
Q&As Helped to Solve: 906 [?]
Skill Endorsements: 46 [?]
Featured
 
1
 

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!

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article