?
Solved

Paramaters

Posted on 2003-02-26
6
Medium Priority
?
303 Views
Last Modified: 2010-04-16
Hey,
This program is suppose to take 5 names, alphabetize them, and print them out. It uses records parameters and procedures. I don't relly understand how paramaters work, can someone please explain? Whenever I compile I get an type mismatch error. Heres the program:

program presidents (input, output);
uses
    wincrt;
type
    name=record
    fname,mname,lname:string;
    end;
    arraytype=array [1..5] of name;
var
   card:arraytype;
   i,j:integer;
   temp:name;
             procedure ask (var ccard:arraytype;ii:integer);
begin
     for ii:=1 to 5 do
begin
     writeln('Type in the first name',ii);
     readln(ccard[ii].fname);
     writeln('Type in the middle name');
     readln(ccard[ii].mname);
     writeln('type in the last name');
     readln(ccard[ii].lname);
     clrscr;
end;
end;
             procedure sort (var ttemp:name;ccard:arraytype;ii,jj:integer);
 begin
 for ii:= 1 to 5-1 do
begin
     for jj:=1 to 5-1 do
begin
     if (ccard[jj].lname) > (ccard[jj+1].lname) then
begin
    ttemp:=ccard[jj];
    ccard[jj]:=ccard[jj+1];
    ccard[jj+1]:=ttemp;
end;
end;
end;
end;
               procedure print (var ccard:arraytype;ii:integer);
begin
     for ii:=1 to 5 do
begin
      writeln(ii,'. ',ccard[i].fname,' ',ccard[i].mname,' ',ccard[i].lname); {do I define .lname as a paramater?}
end;
    writeln('Brian Abbott');
end;
begin
     ask (card,i);
     sort (card,temp); {Error message is here}
     print(card,i);
end.

0
Comment
Question by:brianrhg
  • 4
  • 2
6 Comments
 
LVL 15

Expert Comment

by:VGR
ID: 8026095
well, given the way it's written, no surprise you don't understand it quickly :D

ok, the main program : last three lines.
Call ask(card,i), then sort(), then print().
i is an integer, temp is a record of type "name", and card is an array[1..5] of that "name" type (hence records)

ok until now ?

ask() is pretty straithforward, as is print()

Apparently you'll end up with a compilation error on the line calling Sort(card,temp) BECAUSE sort() is defined this way (signature, prototype, whatever) :
procedure sort (var ttemp:name;ccard:arraytype;ii,jj:integer);

so it REQUIRES two extra parameters of type integer.

Given the body of the sort() procedure, you mistyped the declaration of the procedure sort().
It should read :
procedure sort (var ttemp:name;ccard:arraytype);
 Var ii,jj:integer;

A part from this (your program will work seamlessly after this correction), I suggest you use the text editor to replace all "5" by "cMax" and define cMax after the "uses WinCrt;" line as :
Const cMax=5; // now easily modifiable for program's expansion.

PS : there are no procedure parameters in this program.

regards,
0
 
LVL 15

Expert Comment

by:VGR
ID: 8026121
and if ever this tells you something, Pascal records are just C "structs" (variant types included)
0
 

Author Comment

by:brianrhg
ID: 8036079
I still get the type mismatch error. I'm not sure if I did exactly what you said. I also doubled up the three i's at the print line.  heres the new program.


program presidents (input, output);
uses
    wincrt;
type
    name=record
    fname,mname,lname:string;
    end;
    arraytype=array [1..5] of name;
var
   card:arraytype;
   i,j:integer;
   temp:name;
             procedure ask (var ccard:arraytype;ii:integer);
begin
     for ii:=1 to 5 do
begin
     writeln('Type in the first name',ii);
     readln(ccard[ii].fname);
     writeln('Type in the middle name');
     readln(ccard[ii].mname);
     writeln('type in the last name');
     readln(ccard[ii].lname);
     clrscr;
end;
end;
             procedure sort (var ttemp:name;ccard:arraytype);
VAR ii,jj:integer;          
 begin
 for ii:= 1 to 5-1 do
begin
     for jj:=1 to 5-1 do
begin
     if (ccard[jj].lname) > (ccard[jj+1].lname) then
begin
    ttemp:=ccard[jj];
    ccard[jj]:=ccard[jj+1];
    ccard[jj+1]:=ttemp;
end;
end;
end;
end;
               procedure print (var ccard:arraytype;ii:integer);
begin
     for ii:=1 to 5 do
begin
      writeln(ii,'. ',ccard[ii].fname,' ',ccard[ii].mname,' ',ccard[ii].lname);
end;
    writeln('Brian Abbott');
end;
begin
     ask (card,i);
     sort (card,temp);{type mismatch error}
     print(card,i);
end.



0
[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

 
LVL 15

Expert Comment

by:VGR
ID: 8036134
of course
the call is sort(temp,card), not card,temp

look at the definition
0
 

Author Comment

by:brianrhg
ID: 8041809
Hey, I still getthe same error at the call.
program presidents (input, output);
uses
    wincrt;
type
    name=record
    fname,mname,lname:string;
    end;
    arraytype=array [1..5] of name;
var
   card:arraytype;
   i,j:integer;
   temp:name;
             procedure ask (var ccard:arraytype;ii:integer);
begin
     for ii:=1 to 5 do
begin
     writeln('Type in the first name',ii);
     readln(ccard[ii].fname);
     writeln('Type in the middle name');
     readln(ccard[ii].mname);
     writeln('type in the last name');
     readln(ccard[ii].lname);
     clrscr;
end;
end;
             procedure sort (var ttemp:name;ccard:arraytype);
             Var ii,jj:integer;
         
 begin
 for ii:= 1 to 5-1 do
begin
     for jj:=1 to 5-1 do
begin
     if (ccard[jj].lname) > (ccard[jj+1].lname) then
begin
    ttemp:=ccard[jj];
    ccard[jj]:=ccard[jj+1];
    ccard[jj+1]:=ttemp;
end;
end;
end;
end;
               procedure print (var ccard:arraytype;ii:integer);
begin
     for ii:=1 to 5 do
begin
      writeln(ii,'. ',ccard[ii].fname,' ',ccard[ii].mname,' ',ccard[ii].lname);
end;
    writeln('Brian Abbott');
end;
begin
     ask (card,i);
     sort (card,temp);
     print(card,i);
end.

0
 
LVL 15

Accepted Solution

by:
VGR earned 200 total points
ID: 8042352
begin
    ask (card,i);
    sort (TEMP, CARD);
    print(card,i);
end

read me !!! TEMP, CARD, not CARD, TEMP
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you a startup company? Being a startup, you may be using shared hosting, or maybe even dedicated hosting. But have you ever given a thought to using cloud computing now? Yes, don’t be surprised, it is possible for startups to opt for cloud compu…
"Day by day nothing changes but when u look back, everything is different". That quote precisely describes today’s digital era. For example, you may not have noticed the change, but Voice Search is now all around us.
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…

569 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question