?
Solved

Paramaters

Posted on 2003-02-26
6
Medium Priority
?
302 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

 
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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

The well known Cerber ransomware continues to spread this summer through spear phishing email campaigns targeting enterprises. Learn how it easily bypasses traditional defenses - and what you can do to protect your data.
The Summer 2017 Scholarship Winners have been announced!
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

770 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