Turbo Pascal 7.0 help needed

Yes, I am another college student seeking help with an assignment, and no, I am not trying to find someone to do it all for me. I have been working on it since last Thursday. It is a problem designed to test one's knowledge of procedures. It should be simple enough, but for some reason, I just don't get procedures yet.

It is a problem to calculate the total cost of performing a paint job on 1 or more rooms. The program is designed to ask the user to input the number of rooms to be painted, the square footage of the room(s)(it is assumed for this assignment that the square footage of each room is the same; also we don't use the program to calculate the square footage...we just input an arbitrary number for square footage--after all, we're beginners), and the cost per gallon of paint used for the painting job.

Some information that is given includes: for every 100 square feet, one gallon of paint and 8 hours of labor is required. The labor charge is 18 dollars per hour.

We are supposed to use 3 procedures, passing parameters to the procedures without referencing global variables (I know it's bad programming to do that, but I could probably figure it out more easily if I were allowed to do that.

The first one of the procedures is supposed to accept input from the user, and that input is to be passed as a parameter (THIS IS ONE OF THE AREAS I'M HUNG UP ON) as well as input validation for the input that is accepted. You can't accept a value less than one for number of rooms, or a value less than $10.00 for cost of paint per gallon. Also, square footage is required to be a positive integer value.

The second procedure is supposed to calculate all the required details--gallons and cost of paint required, hours and labor charges, and total cost. As the instructions state, " be sure to properly pass parameters containing the needed inputs for the calculations, as well as parameters to return the calculated values".

The final procedure is to print: the # of gallons of paint required, the hours of labor required, the cost of the paint, the labor charges and the total cost of the the paint job. The calculated values are to be passed as parameters.

I don't quite understand yet how to pass a parameter, because I'm still not sure what that entails. I've been looking in books and on the web, and so far, nothing has helped me out that much.


I know that is a lot of info to digest, and I think I have the sequencing down, it's the calling and passing parameters stuff (the focus of the assignment) that I'm still confused about. I prefer not to post what I have done so far on the board...I'd rather email it to you. But if you insist I post it, leave a reply saying so, and I will make a fool out of myself by showing how little I know about programming. Thanks in advance.

Comments

  • Okay...I'll just get over myself and show you the skeleton I have so far. Please, don't laugh. I am still an extreme newbie. I realize that there are some problems in it already...I am modeling this from a similar problem I've seen and trying to figure out the syntax. Here it is:


    Program paintjob;

    procedure InputSub(var RoomNumber, Area : integer; PPG : real);
    begin
    WRITE(How many rooms are to be painted? );
    READ(RoomNumber};
    WRITE(What is the area of each room? );
    READ(Area);
    WRITE(What is the cost per gallon of paint?);
    READ(PPG);
    end;

    procedure CalculateSub(Gallons, Hours : integer; Labor, PaintCost, TotalCost : Real)
    begin
    Gallons := RoomNumber * Area/100
    Hours := Gallons * 8
    Labor := Hours * 18.00
    PaintCost := PPG * Gallons
    TotalCost := PaintCost + Labor
    end;

    procedure PrintSub();
    begin
    WRITE(The number of gallons of paint required is );
    WRITE(The hours of labor required are ');
    WRITE(The cost of the paint is );
    WRITE(The labor charges are );
    WRITE(The total cost of the job is ');
    end;

    begin
    InputSub();
    CalculateSub();
    Printsub();
    end.

  • : Okay...I'll just get over myself and show you the skeleton I have so far. Please, don't laugh. I am still an extreme newbie. I realize that there are some problems in it already...I am modeling this from a similar problem I've seen and trying to figure out the syntax. Here it is:
    :
    :
    : Program paintjob;
    :
    : procedure InputSub(var RoomNumber, Area : integer; PPG : real);
    : begin
    : WRITE(How many rooms are to be painted? );
    : READ(RoomNumber};
    : WRITE(What is the area of each room? );
    : READ(Area);
    : WRITE(What is the cost per gallon of paint?);
    : READ(PPG);
    : end;
    :
    : procedure CalculateSub(Gallons, Hours : integer; Labor, PaintCost, TotalCost : Real)
    : begin
    : Gallons := RoomNumber * Area/100
    : Hours := Gallons * 8
    : Labor := Hours * 18.00
    : PaintCost := PPG * Gallons
    : TotalCost := PaintCost + Labor
    : end;
    :
    : procedure PrintSub();
    : begin
    : WRITE(The number of gallons of paint required is );
    : WRITE(The hours of labor required are ');
    : WRITE(The cost of the paint is );
    : WRITE(The labor charges are );
    : WRITE(The total cost of the job is ');
    : end;
    :
    : begin
    : InputSub();
    : CalculateSub();
    : Printsub();
    : end.
    :
    :
    It looks quite well, but there are a few errors in it:
    - Throughout your code you've used ` for string constants, while it needs to be '.
    - I would suggest that you make all your variables reals, because the number of gallons and hours can be fractional. If you want to still use integers for those, you have to convert reals to integers. There are several functions for that, like Round(). The help files can show you how to use them.
    - The var parameter type will not be used after a ";". This will produce a wrong result in the InputSub(); procedure. You should change the header to:
    [code]
    procedure InputSub(var RoomNumber, Area : integer; [red]var[/red] PPG : real);
    [/code]
    to be able to truly enter the value for the PPG. This also holds true for the CalculateSub().
    - Pascal knows two scopes for variables: local and global. Global variables are variables, which exist throughout the entire program, while local variables only exist within a single procedure or function. In your program you have only declared local variables. The RoomNumber variable, for example, is only declared for the InputSub() and not for the CalculateSub(). Should you compile this code, you will get an "unknown identifier"-error in the CalculateSub(). My suggestion is to make all the variables global variables. Here is an example of how to declare a few global variables:
    [code]
    program paintjob;
    var { Declare global vars }
    RoomNumber, Area : integer;
    PPG : real

    procedure InputSub(SomeLocalVar1: integer);
    var
    SomeLocalVar2: integer; { two examples of local vars }
    begin
    { Statements here }
    end;

    procedure CalculateSub;
    begin
    { Statements here }
    SomeLocalVar2 := 0; { "Unknown identifier"-error }
    end;
    [/code]
    - Write() doesn't add a line ending to the information to be shown. Thus the PrintSub() will give you the following result:
    [code]
    The number of gallons of paint required is The hours of labor required are The
    cost of the paint is The labor charges are The total cost of the job is
    [/code]
    If you want to have line-endings after the write, you need to use the WriteLn() procedure. Also Write()/Writeln() are very unPascal-like, as their parameter-list is not fixed as in other procedure. Here are some examples of valid write()/writeln()'s:
    [code]
    var
    Age: integer;
    Length: real;
    Name: string;

    writeln;
    write('hello world');
    writeln('Hi, I am ', Name);
    writeln('My age is ', Age);
    writeln('I am ', Length, ' inches long.');
    writeln('Hi, I am ', Name, ', and I am ', Age,
    ' years old, and grown to ', Length, ' inches.');
    [/code]
    This is also necessary to know, because your program doesn't write the values it just calculated.

    There are a few other mistakes, but you might find them yourself. If not feel free to ask.
  • [b][red]This message was edited by computerfrog at 2004-7-23 7:55:16[/red][/b][hr]


    Thank you for replying. Yes, there are still parts of the overall program that have yet to be filled in, as this is just a skeleton converted from pseudocode, and I hadn't yet taken out some of the typos, like using } instead of ), or not using the single '. Typically, I prefer to use writeln statements as opposed to write statements; write statements are used here only because that is how I write them when trying to come up with pseudocode for a program to make writing it more efficient.

    Before I read your reply, I did learn from reading in another book about the difference between value parameters and var parameters, and that by adding the semicolon, what was intended to be a var parameter became a value parameter. I have gone back and changed the values of all the variables so fair to REALs instead of INTEGERs; I only used integers because the instructor discourages always using REALs, since there are times when integers will work better. Like you, it makes sense to use reals since those data types that were listed as integers could be real values. Since this is a beginning programming class, the instructor said that we could assume those numbers are whole numbers (area, paintcost, etc.)

    I keep re-reading material on procedures--what they are, what they do and how to use them, and for some reason, I'm a little slow on the uptake here. If I understand procedures correctly, a procedure is similar to the main program (a subprogram if you will). The purpose of procedures is to modularize a large program, to help to avoid repeating code over and over again. I understand you must define the procedure before it can be called, so a procedure must appear before the main body of the program to call it. I understand that parameters are how the main program communicates with the procedure (or one procedure communicates with another procedure). I understand that if any variables are declared before a procedure then they are global variables, whereas variables declared in a procedure are local variables.

    So, to use a procedure, you have to define that procedure before it can be called by the program. To call the procedure, you use its name as a statement in the main program, with the actual parameters in parentheses following the procedure name. But this is the point where I get confused.

    The instructions to this assigment say that WE CANNOT REFERENCE GLOBAL VARIABLES, which is why I have only local variables defined. So, I'm not sure how exactly I'm supposed to make this program take input from a user on number of rooms to be painted, how many square feet for the rooms, and how much paint costs per gallon--and then use a procedure to calculate gallons and cost of paint required, hours of labor and labor charges, and total cost of the entire paint job. If I am not allowed to use global variables, how can I get the information from a procedure to the main program, or from one procedure to another to help pass this information along in a meaningful way? I can't seem to figure this part out. Any suggestions? I'm going to be working on this as long as it takes until I get it done, and I appreciate your input so far. I'll check back here periodically to see if anyone has some insight to share here, and if I make any changes to the program, I'll re-display them.

    I am going to change some of the variable names to include a verb to better reflect what their purpose is.


  • [b][red]This message was edited by zibadian at 2004-7-23 9:13:44[/red][/b][hr]
    : [b][red]This message was edited by computerfrog at 2004-7-23 7:55:16[/red][/b][hr]
    :
    :
    : Thank you for replying. Yes, there are still parts of the overall program that have yet to be filled in, as this is just a skeleton converted from pseudocode, and I hadn't yet taken out some of the typos, like using } instead of ), or not using the single '. Typically, I prefer to use writeln statements as opposed to write statements; write statements are used here only because that is how I write them when trying to come up with pseudocode for a program to make writing it more efficient.
    :
    : Before I read your reply, I did learn from reading in another book about the difference between value parameters and var parameters, and that by adding the semicolon, what was intended to be a var parameter became a value parameter. I have gone back and changed the values of all the variables so fair to REALs instead of INTEGERs; I only used integers because the instructor discourages always using REALs, since there are times when integers will work better. Like you, it makes sense to use reals since those data types that were listed as integers could be real values. Since this is a beginning programming class, the instructor said that we could assume those numbers are whole numbers (area, paintcost, etc.)
    :
    : I keep re-reading material on procedures--what they are, what they do and how to use them, and for some reason, I'm a little slow on the uptake here. If I understand procedures correctly, a procedure is similar to the main program (a subprogram if you will). The purpose of procedures is to modularize a large program, to help to avoid repeating code over and over again. I understand you must define the procedure before it can be called, so a procedure must appear before the main body of the program to call it. I understand that parameters are how the main program communicates with the procedure (or one procedure communicates with another procedure). I understand that if any variables are declared before a procedure then they are global variables, whereas variables declared in a procedure are local variables.
    :
    : So, to use a procedure, you have to define that procedure before it can be called by the program. To call the procedure, you use its name as a statement in the main program, with the actual parameters in parentheses following the procedure name. But this is the point where I get confused.
    :
    : The instructions to this assigment say that WE CANNOT REFERENCE GLOBAL VARIABLES, which is why I have only local variables defined. So, I'm not sure how exactly I'm supposed to make this program take input from a user on number of rooms to be painted, how many square feet for the rooms, and how much paint costs per gallon--and then use a procedure to calculate gallons and cost of paint required, hours of labor and labor charges, and total cost of the entire paint job. If I am not allowed to use global variables, how can I get the information from a procedure to the main program, or from one procedure to another to help pass this information along in a meaningful way? I can't seem to figure this part out. Any suggestions? I'm going to be working on this as long as it takes until I get it done, and I appreciate your input so far. I'll check back here periodically to see if anyone has some insight to share here, and if I make any changes to the program, I'll re-display them.
    :
    : I am going to change some of the variable names to include a verb to better reflect what their purpose is.
    :
    :
    :
    You can declare local variables with the main body as well:
    [code]
    procedure SomeProc(var SomeInt: integer);
    begin
    readln(SomeInt);
    end;

    procedure AnotherProc(SomeInt: integer);
    begin
    writeln(SomeInt);
    end;

    var
    AnotherInt: integer; {This integer only exists locally for the main program body}
    begin
    SomeProc(AnotherInt);
    AnotherProc(AnotherInt);
    end.
    [/code]
    If you run this program you will see the value entered in SomeProc() repeated on the screen.

    Procedures and functions are actually new Pascal words, which you create. A lot of the higher Pascal words (like Copy(), Pos(), Length(), etc) can be recreated in the language. There are very few Pascal words, which the compiler handles in a special way, readln() and writeln() for example.

    As for not allowing to se global variables, that is simply foolish. That will only limit your options and reduce performance. I have created programs which operate on large quantities of data (200 kB or more). When face with such amounts of data you have to store it globally, because the local stack can only hold 64 kB. Your instructor should also consider that sometimes a procedure needs 10's of different variables, which can be a pain in the ... to pass as parameters. And in every call all those values have to be copied from one location to another.
  • [b][red]This message was edited by computerfrog at 2004-7-23 12:20:3[/red][/b][hr]
    [b][red]This message was edited by computerfrog at 2004-7-23 12:8:33[/red][/b][hr]

    [b]Question:[/b] A global variable is one that is declared in the main program and can be referenced from any point FOLLOWING its declaration. So, If I were to write a program with this structure:

    program AB;
    var A, B;

    Procedure ONE;
    procedure TWO;

    begin (*main body of program*)
    A;
    B;
    end.

    Then Procedure ONE and Procedue TWO can reference global variables A & B, right? [b]BUT...if the structure of the program were like this:[/b]

    program ;
    procedure ONE;
    procedure TWO;

    begin

    Var A,B

    ONE;
    TWO;
    end.

    where Vars A and B are physically defined AFTER procedure ONE and TWO are defined, are A and B still considered Global variables that the procedures can reference? Or is the position of Var A and Var B relevant?








  • [b][red]This message was edited by computerfrog at 2004-7-23 12:21:42[/red][/b][hr]
    this is the program I have done so far, and it achieves the desired output...I still need to add a few conditionals to InputSub to verify that the user is entering the appropriate information...and I'm not sure if what I've written is considered as referencing global variables or not...but at least it works for now!

    That's why I asked the question in my reponse above about the physical position of declaring variables before or after procedures are defined. If, defining procedures before declaring main program variables is what it takes to make this a program that does not access global variables, then I'm almost done. If, however, what I have done is reference a global variable in my procedures, I still have a lot of work to do.

    Here it is:

    [b]Program paintjob(input,output);
    uses crt; {To clear screen for each new entry}

    procedure InputSub(var GetRoomNumber, GetArea, GetPPG : real);
    {var parameter used so that values can be input by the user}
    {"PPG" is acronym representing "Price Per Gallon"}

    begin
    Write(' How many rooms are to be painted? ');
    Readln(GetRoomNumber);
    write(' What is the area of each room? ');
    readln(GetArea);
    write(' What is the cost per gallon of paint? $');
    readln(GetPPG);
    end;

    procedure CalculateSub(var GetGallons, GetRoomNumber, GetArea,
    GetHours, GetPPG, GetLabor, GetPaintCost, TotalCost : Real);

    begin
    GetGallons := GetRoomNumber * GetArea/100;
    GetHours := GetGallons * 8;
    GetLabor := GetHours * 18.00 ;
    GetPaintCost := GetPPG * GetGallons ;
    TotalCost := GetPaintCost + GetLabor ;
    end;{procedure calculatesub}

    procedure PrintSub(GetGallons, GetHours, GetPaintcost, GetLabor, TotalCost: Real);
    begin
    writeln; { To clean up the appearance of the output }
    writeln; { statements and the output statements }

    Writeln(' The number of GALLONS of PAINT required is: ', GetGallons :2:2);
    Writeln; {to neaten appearance of last output }
    Writeln(' The total HOURS of LABOR required are: ', GetHours :2:2);
    Writeln; {to neaten appearance of last output }
    Writeln(' The total COST of the PAINT is: $', GetPaintCost :2:2);
    Writeln; {to neaten appearance of last output }
    Writeln(' The total LABOR CHARGES are: $', GetLabor :2:2);
    Writeln; {to neaten appearance of last output }

    Writeln; {to neaten appearance of last output }
    Writeln; {to neaten appearance of last output }
    Writeln; {to neaten appearance of last output }
    Writeln(' THE TOTAL COST OF THE PAINT JOB IS: $', TotalCost :2:2);
    end;

    var
    Getroomnumber, GetArea, GetPPG,GetGallons, GetHours,
    GetLabor, GetPaintCost, TotalCost: real;

    begin {main program}
    clrscr; {To clear screen for each new entry}

    InputSub(GetRoomNumber, GetArea, GetPPG);
    CalculateSub(GetGallons, GetRoomnumber, GetArea, GetHours,
    GetPPG, GetLabor, GetPaintCost, TotalCost);
    Printsub(GetGallons, GetHours, GetPaintcost, GetLabor, TotalCost);

    end.



  • : [b][red]This message was edited by computerfrog at 2004-7-23 12:20:3[/red][/b][hr]
    : [b][red]This message was edited by computerfrog at 2004-7-23 12:8:33[/red][/b][hr]
    :
    : [b]Question:[/b] A global variable is one that is declared in the main program and can be referenced from any point FOLLOWING its declaration. So, If I were to write a program with this structure:
    :
    : program AB;
    : var A, B;
    :
    : Procedure ONE;
    : procedure TWO;
    :
    : begin (*main body of program*)
    : A;
    : B;
    : end.
    :
    : Then Procedure ONE and Procedue TWO can reference global variables A & B, right? [b]BUT...if the structure of the program were like this:[/b]
    :
    : program ;
    : procedure ONE;
    : procedure TWO;
    :
    : begin
    :
    : Var A,B
    :
    : ONE;
    : TWO;
    : end.
    :
    : where Vars A and B are physically defined AFTER procedure ONE and TWO are defined, are A and B still considered Global variables that the procedures can reference? Or is the position of Var A and Var B relevant?
    :
    :
    The position of vars A & B is relevant. Pascal reads the file from the top down, so the place of the declaration determines, which procedures/functions can use it. You are in fact defining new Pascal words each time you declare a variable or a procedure/function. From the ";" following the declaration, it can be used, and not before it.
    In your second code, A & B are considered local and not global variables for the body only. In this case A & B cannot be used by any of the procedures.
  • : [b][red]This message was edited by computerfrog at 2004-7-23 12:21:42[/red][/b][hr]
    : this is the program I have done so far, and it achieves the desired output...I still need to add a few conditionals to InputSub to verify that the user is entering the appropriate information...and I'm not sure if what I've written is considered as referencing global variables or not...but at least it works for now!
    :
    : That's why I asked the question in my reponse above about the physical position of declaring variables before or after procedures are defined. If, defining procedures before declaring main program variables is what it takes to make this a program that does not access global variables, then I'm almost done. If, however, what I have done is reference a global variable in my procedures, I still have a lot of work to do.
    :
    : Here it is:
    :
    : [b]Program paintjob(input,output);
    : uses crt; {To clear screen for each new entry}
    :
    : procedure InputSub(var GetRoomNumber, GetArea, GetPPG : real);
    : {var parameter used so that values can be input by the user}
    : {"PPG" is acronym representing "Price Per Gallon"}
    :
    : begin
    : Write(' How many rooms are to be painted? ');
    : Readln(GetRoomNumber);
    : write(' What is the area of each room? ');
    : readln(GetArea);
    : write(' What is the cost per gallon of paint? $');
    : readln(GetPPG);
    : end;
    :
    : procedure CalculateSub(var GetGallons, GetRoomNumber, GetArea,
    : GetHours, GetPPG, GetLabor, GetPaintCost, TotalCost : Real);
    :
    : begin
    : GetGallons := GetRoomNumber * GetArea/100;
    : GetHours := GetGallons * 8;
    : GetLabor := GetHours * 18.00 ;
    : GetPaintCost := GetPPG * GetGallons ;
    : TotalCost := GetPaintCost + GetLabor ;
    : end;{procedure calculatesub}
    :
    : procedure PrintSub(GetGallons, GetHours, GetPaintcost, GetLabor, TotalCost: Real);
    : begin
    : writeln; { To clean up the appearance of the output }
    : writeln; { statements and the output statements }
    :
    : Writeln(' The number of GALLONS of PAINT required is: ', GetGallons :2:2);
    : Writeln; {to neaten appearance of last output }
    : Writeln(' The total HOURS of LABOR required are: ', GetHours :2:2);
    : Writeln; {to neaten appearance of last output }
    : Writeln(' The total COST of the PAINT is: $', GetPaintCost :2:2);
    : Writeln; {to neaten appearance of last output }
    : Writeln(' The total LABOR CHARGES are: $', GetLabor :2:2);
    : Writeln; {to neaten appearance of last output }
    :
    : Writeln; {to neaten appearance of last output }
    : Writeln; {to neaten appearance of last output }
    : Writeln; {to neaten appearance of last output }
    : Writeln(' THE TOTAL COST OF THE PAINT JOB IS: $', TotalCost :2:2);
    : end;
    :
    : var
    : Getroomnumber, GetArea, GetPPG,GetGallons, GetHours,
    : GetLabor, GetPaintCost, TotalCost: real;
    :
    : begin {main program}
    : clrscr; {To clear screen for each new entry}
    :
    : InputSub(GetRoomNumber, GetArea, GetPPG);
    : CalculateSub(GetGallons, GetRoomnumber, GetArea, GetHours,
    : GetPPG, GetLabor, GetPaintCost, TotalCost);
    : Printsub(GetGallons, GetHours, GetPaintcost, GetLabor, TotalCost);
    :
    : end.
    :
    :
    I wouldn't use any verbs in variable names. Usually verbs are only used in procedure or function names, because they actually do something. Thus the name GetGallons implies to be a function, which calculates the gallons of something. The variable Gallons holds the value as calculated by GetGallons. In this case it doesn't matter much, but later on you will get into trouble with the names. Here is an example from one of my programs:
    [code]

    var
    Values: array[0..100] of double;

    function GetValue(index: integer): double;
    { Get a single value from the Values array }
    begin
    GetValue := Values[index];
    end;

    procedure SetValue(index: integer; NewValue: string);
    { Place a single value (as a string) into the Values array }
    var
    c: integer;
    begin
    Val(NewValue, Values[index], c);
    end;
    [/code]
    As you can see I used the verbs to indicate a code, while the variable names have a more static feel about them.

    These naming rules aren't written in stone, but they are recognized and made "official" by Borland. Most Pascal and Delphi programmers know those rules and create their expectations based on them.
  • [b][red]This message was edited by computerfrog at 2004-7-23 13:34:51[/red][/b][hr]
    So does that mean then that my program (even if I should take the "get" out of the variable names) that I my program is in fact calling local and not global variables??? [b]Woooohoooo!!!![/b]

    If so, I am one happy individual!!!!

    BTW--before I forget to tell you,

    [b]THANK YOU SO MUCH FOR YOUR HELP!!!!!
    This is starting to make sense to me...[/b]

    I will change the var names and then repost to see what you think about it.





  • [b]This is the final version of the program. It compiles and works as it should...So long as the procedures don't make reference to global variables, I'm safe...[/b]



    Program paintjob(input,output);
    uses crt;

    procedure InputSub(var RoomNumber, Area, PPG : real);
    {var parameter used so that values can be input by the user}
    {"PPG" is acronym representing "Price Per Gallon"}

    begin
    textcolor(white);
    Writeln('----------------------------------------------------------');
    {to give a more user-friendly output}
    writeln('Paint Calcuation * * * * * * * * * * * * * * * * * * * * *');
    Writeln('----------------------------------------------------------');
    writeln;
    Write(' How many rooms are to be painted? ');
    readln (Roomnumber);

    while (Roomnumber< 1) do begin

    writeln('Roomnumber must be one or more');

    readln (RoomNumber);

    end;

    write(' What is the area of each room? ');
    readln(Area);
    while(Area < 1) do begin
    writeln('Area must be a positive number');
    readln(Area);
    end;

    write(' What is the price per gallon of paint? $');
    readln(PPG);
    while(PPG < 10.00) do begin
    writeln('PPG must be $10 or more.');
    readln(PPG)
    end;
    end;

    procedure CalculateSub(var Gallons, RoomNumber, Area,
    Hours, PPG, Labor, PaintCost, TotalCost : Real);

    begin
    Gallons := RoomNumber * Area/100;
    Hours := Gallons * 8;
    Labor := Hours * 18.00 ;
    PaintCost := PPG * Gallons ;
    TotalCost := PaintCost + Labor ;
    end;{procedure calculatesub}

    procedure PrintSub(Gallons, Hours, Paintcost, Labor,
    TotalCost: Real);
    begin

    writeln; { To clean up the appearance of the final output }
    writeln;
    writeln('- - - - - - - - - - - - - - - - - - - - - - - - - - - - - ');
    writeln;
    Writeln(' The number of GALLONS of PAINT required is: ', Gallons :2:2);
    Writeln(' The total HOURS of LABOR required are: ', Hours :2:2);
    Writeln(' The total COST of the PAINT is: $', PaintCost :2:2);
    Writeln(' The total LABOR CHARGES are: $', Labor :2:2);
    Writeln;
    Writeln('----------------------------------------------------------');
    Textcolor(red);
    Writeln(' THE TOTAL COST OF THE PAINT JOB IS: $', TotalCost :2:2);
    Textcolor(white);
    Writeln('----------------------------------------------------------');
    Writeln;
    Writeln('NEXT JOB:');
    Writeln;
    (* Since the program is currently set not to clear the screen
    (to allow the user to see the cost of several different projects
    on screen at the same time,spaces and text have been added to keep the
    output of one calculation from running into another *)

    end;

    var
    roomnumber, Area, PPG, Gallons, Hours,
    Labor, PaintCost, TotalCost: real;

    begin {main program}

    clrscr;
    {The "clrscr;" has been commented out so that the user
    can remove the comment brackets to activate the clear screen function
    at a later date, if desired}

    InputSub(RoomNumber, Area, PPG);
    CalculateSub(Gallons, Roomnumber, Area,Hours,
    PPG, Labor, PaintCost, TotalCost);
    Printsub(Gallons, Hours, Paintcost, Labor, TotalCost);
    writeln; {To give space between next input session}

    end.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories