Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Invalid Variable Reference?

FyreAndIce83FyreAndIce83 Posts: 13Member
First...I don't know what the error means but...could someone please offer me a hand as to why the error is there and how I can get rid of it to finish this program. Remember, this is just a fragment so far...

PROGRAM Charges;
USES CRT;

VAR

UserAccount : String[5];
PriorityCode, NumberCustomer : Integer;
UseHours, HourCharge, AveCharge, PriorityCharge, TotalCharge : Real;

Procedure Headings;

Begin

Writeln(' Apex Computer Service');
Writeln;
Writeln(' Account Charge');
Writeln(' --------- --------');

End;

Procedure GetInfo;

Begin

Writeln(' Please Input Your User Account Number: ');
Readln(UserAccount);
Writeln(' Please Input Your Priority Code: ');
Readln(PriorityCode);
Writeln(' Please Input Your Hours of Usage: ');
Readln(UseHours);

End;

Procedure LoopingIt;

Begin

WHILE UserAccount <> 'xxxxx' DO

Begin

IF (UseHours > 15.00) THEN
HourCharge := (225.00 + (15.00 * UseHours))

ELSE (UseHours > 5.00) AND (UseHours <= 15.00)
HourCharge := (100.00 + (25.00 * UseHours))

ELSE
HourCharge := 100.00;

End;
End;
End;

BEGIN

CLRSCR;
Headings;
GetInfo;
LoopingIt;
CalcCharge;

END.

«1

Comments

  • zibadianzibadian Posts: 6,349Member
    : First...I don't know what the error means but...could someone please offer me a hand as to why the error is there and how I can get rid of it to finish this program. Remember, this is just a fragment so far...
    :
    : PROGRAM Charges;
    : USES CRT;
    :
    : VAR
    :
    : UserAccount : String[5];
    : PriorityCode, NumberCustomer : Integer;
    : UseHours, HourCharge, AveCharge, PriorityCharge, TotalCharge : Real;
    :
    : Procedure Headings;
    :
    : Begin
    :
    : Writeln(' Apex Computer Service');
    : Writeln;
    : Writeln(' Account Charge');
    : Writeln(' --------- --------');
    :
    : End;
    :
    : Procedure GetInfo;
    :
    : Begin
    :
    : Writeln(' Please Input Your User Account Number: ');
    : Readln(UserAccount);
    : Writeln(' Please Input Your Priority Code: ');
    : Readln(PriorityCode);
    : Writeln(' Please Input Your Hours of Usage: ');
    : Readln(UseHours);
    :
    : End;
    :
    : Procedure LoopingIt;
    :
    : Begin
    :
    : WHILE UserAccount <> 'xxxxx' DO
    :
    : Begin
    :
    : IF (UseHours > 15.00) THEN
    : HourCharge := (225.00 + (15.00 * UseHours))
    :
    : ELSE (UseHours > 5.00) AND (UseHours <= 15.00)
    : HourCharge := (100.00 + (25.00 * UseHours))
    :
    : ELSE
    : HourCharge := 100.00;
    :
    : End;
    : End;
    : End;
    :
    : BEGIN
    :
    : CLRSCR;
    : Headings;
    : GetInfo;
    : LoopingIt;
    : CalcCharge;
    :
    : END.
    :
    :
    The "Invalid Variable Reference" means that the compiler cannot a certain statement, unless the variables it uses are of identical formats.
    Given the fact that you want us to guess where the error occurred, my guess is that it occurred in the while-do. You could try to solve it by changing the type of the UserAccount into a normal string.
    Also you have created an infinite loop, because the user cannot change the UserAccount from within the while-do.
  • PerranPerran Posts: 241Member
    : First...I don't know what the error means but...could someone please offer me a hand as to why the error is there and how I can get rid of it to finish this program. Remember, this is just a fragment so far...
    :
    : PROGRAM Charges;
    : USES CRT;
    :
    : VAR
    :
    : UserAccount : String[5];
    : PriorityCode, NumberCustomer : Integer;
    : UseHours, HourCharge, AveCharge, PriorityCharge, TotalCharge : Real;
    :
    : Procedure Headings;
    :
    : Begin
    :
    : Writeln(' Apex Computer Service');
    : Writeln;
    : Writeln(' Account Charge');
    : Writeln(' --------- --------');
    :
    : End;
    :
    : Procedure GetInfo;
    :
    : Begin
    :
    : Writeln(' Please Input Your User Account Number: ');
    : Readln(UserAccount);
    : Writeln(' Please Input Your Priority Code: ');
    : Readln(PriorityCode);
    : Writeln(' Please Input Your Hours of Usage: ');
    : Readln(UseHours);
    :
    : End;
    :
    : Procedure LoopingIt;
    :
    : Begin
    :
    : WHILE UserAccount <> 'xxxxx' DO
    :
    : Begin
    :
    : IF (UseHours > 15.00) THEN
    : HourCharge := (225.00 + (15.00 * UseHours))
    :
    : ELSE (UseHours > 5.00) AND (UseHours <= 15.00)
    : HourCharge := (100.00 + (25.00 * UseHours))
    :
    : ELSE
    : HourCharge := 100.00;
    :
    : End;
    : End;
    : End;
    :
    : BEGIN
    :
    : CLRSCR;
    : Headings;
    : GetInfo;
    : LoopingIt;
    : CalcCharge;
    :
    : END.
    :
    :
    In addition to Zibadian's comments, I would like to point out that there is a call to "CalcCharge" which doesn't appear to exist.
  • FyreAndIce83FyreAndIce83 Posts: 13Member
    (Initial Code Was Here)
    : In addition to Zibadian's comments, I would like to point out that there is a call to "CalcCharge" which doesn't appear to exist.
    :

    Alright, I changed some things, but am getting an error compiling using a procedure in the loop. I believe it is the CalcCharge procedure that contains the error. Please let me know how to fix it?

    PROGRAM Charges;
    USES CRT;

    VAR

    UserAccount : String;
    PriorityCode, NumberCustomer : Integer;
    UseHours, HourCharge, AveCharge, PriorityCharge, TotalCharge : Real;

    Procedure Headings;

    Begin

    Writeln(' Apex Computer Service');
    Writeln;
    Writeln(' Account Charge');
    Writeln(' --------- --------');

    End;

    Procedure GetInfo;

    Begin

    Writeln(' Please Input Your User Account Number: ');
    Readln(UserAccount);
    Writeln(' Please Input Your Priority Code: ');
    Readln(PriorityCode);
    Writeln(' Please Input Your Hours of Usage: ');
    Readln(UseHours);

    End;

    Procedure LoopingIt;

    Begin

    WHILE UserAccount <> 'xxxxx' DO

    Begin

    Procedure CalcCharge;

    Begin

    IF (UseHours > 15.00) THEN
    HourCharge := (225.00 + (15.00 * UseHours));

    ELSE (UseHours > 5.00) AND (UseHours <= 15.00)
    HourCharge := (100.00 + (25.00 * UseHours));

    ELSE
    HourCharge := 100.00;

    IF PriorityCode = 0 THEN
    TotalCharge := HourCharge

    ELSE
    PriorityCode = 1 THEN
    TotalCharge := (HourCharge + 50);

    ELSE
    PriorityCode = 2 THEN
    TotalCharge := (HourCharge + 100);

    End;


    Procedure ShowData;

    Begin

    Writeln(Headings);
    Writeln(TotalCharge);

    End;

    GetInfo;
    End;

    BEGIN

    CLRSCR;
    Headings;
    GetInfo;
    LoopingIt;
    CalcCharge;
    ShowData;

    END.

  • delljohnbdelljohnb Posts: 81Member
    : First...I don't know what the error means but...could someone please offer me a hand as to why the error is there and how I can get rid of it to finish this program. Remember, this is just a fragment so far...
    :
    : PROGRAM Charges;
    : USES CRT;
    :
    : VAR
    :
    : UserAccount : String[5];
    : PriorityCode, NumberCustomer : Integer;
    : UseHours, HourCharge, AveCharge, PriorityCharge, TotalCharge : Real;
    :
    : Procedure Headings;
    :
    : Begin
    :
    : Writeln(' Apex Computer Service');
    : Writeln;
    : Writeln(' Account Charge');
    : Writeln(' --------- --------');
    :
    : End;
    :
    : Procedure GetInfo;
    :
    : Begin
    :
    : Writeln(' Please Input Your User Account Number: ');
    : Readln(UserAccount);
    : Writeln(' Please Input Your Priority Code: ');
    : Readln(PriorityCode);
    : Writeln(' Please Input Your Hours of Usage: ');
    : Readln(UseHours);
    :
    : End;
    :
    : Procedure LoopingIt;
    :
    : Begin
    :
    : WHILE UserAccount <> 'xxxxx' DO
    :
    : Begin
    :
    : IF (UseHours > 15.00) THEN
    : HourCharge := (225.00 + (15.00 * UseHours))
    :
    : ELSE (UseHours > 5.00) AND (UseHours <= 15.00)
    : HourCharge := (100.00 + (25.00 * UseHours))
    :
    : ELSE
    : HourCharge := 100.00;
    :
    : End;
    : End;
    : End;
    :
    : BEGIN
    :
    : CLRSCR;
    : Headings;
    : GetInfo;
    : LoopingIt;
    : CalcCharge;
    :
    : END.
    :
    :

    Try making UserAccount a text variable. I had this same problem last week, and I converted to a text variable, and everything worked great. :-)

    I didn't even look into the while loop, the error could still be there. Zibadian is a pretty good programmer, go with his suggestion first, and if that doesn't work, try mine. Good Luck.

    Delljohnb


  • FyreAndIce83FyreAndIce83 Posts: 13Member
    : : First...I don't know what the error means but...could someone please offer me a hand as to why the error is there and how I can get rid of it to finish this program. Remember, this is just a fragment so far...
    : :
    : : PROGRAM Charges;
    : : USES CRT;
    : :
    : : VAR
    : :
    : : UserAccount : String[5];
    : : PriorityCode, NumberCustomer : Integer;
    : : UseHours, HourCharge, AveCharge, PriorityCharge, TotalCharge : Real;
    : :
    : : Procedure Headings;
    : :
    : : Begin
    : :
    : : Writeln(' Apex Computer Service');
    : : Writeln;
    : : Writeln(' Account Charge');
    : : Writeln(' --------- --------');
    : :
    : : End;
    : :
    : : Procedure GetInfo;
    : :
    : : Begin
    : :
    : : Writeln(' Please Input Your User Account Number: ');
    : : Readln(UserAccount);
    : : Writeln(' Please Input Your Priority Code: ');
    : : Readln(PriorityCode);
    : : Writeln(' Please Input Your Hours of Usage: ');
    : : Readln(UseHours);
    : :
    : : End;
    : :
    : : Procedure LoopingIt;
    : :
    : : Begin
    : :
    : : WHILE UserAccount <> 'xxxxx' DO
    : :
    : : Begin
    : :
    : : IF (UseHours > 15.00) THEN
    : : HourCharge := (225.00 + (15.00 * UseHours))
    : :
    : : ELSE (UseHours > 5.00) AND (UseHours <= 15.00)
    : : HourCharge := (100.00 + (25.00 * UseHours))
    : :
    : : ELSE
    : : HourCharge := 100.00;
    : :
    : : End;
    : : End;
    : : End;
    : :
    : : BEGIN
    : :
    : : CLRSCR;
    : : Headings;
    : : GetInfo;
    : : LoopingIt;
    : : CalcCharge;
    : :
    : : END.
    : :
    : :
    :
    : Try making UserAccount a text variable. I had this same problem last week, and I converted to a text variable, and everything worked great. :-)
    :
    : I didn't even look into the while loop, the error could still be there. Zibadian is a pretty good programmer, go with his suggestion first, and if that doesn't work, try mine. Good Luck.
    :
    : Delljohnb
    :
    :
    :
    Ty for the help, but changing the UserAccount into a text variable, it causes a type mismatch in the While Loop. Any clue why?

  • ManningManning Posts: 1,621Member
    : : : First...I don't know what the error means but...could someone please offer me a hand as to why the error is there and how I can get rid of it to finish this program. Remember, this is just a fragment so far...
    : : :
    : : : PROGRAM Charges;
    : : : USES CRT;
    : : :
    : : : VAR
    : : :
    : : : UserAccount : String[5];
    : : : PriorityCode, NumberCustomer : Integer;
    : : : UseHours, HourCharge, AveCharge, PriorityCharge, TotalCharge : Real;
    : : :
    : : : Procedure Headings;
    : : :
    : : : Begin
    : : :
    : : : Writeln(' Apex Computer Service');
    : : : Writeln;
    : : : Writeln(' Account Charge');
    : : : Writeln(' --------- --------');
    : : :
    : : : End;
    : : :
    : : : Procedure GetInfo;
    : : :
    : : : Begin
    : : :
    : : : Writeln(' Please Input Your User Account Number: ');
    : : : Readln(UserAccount);
    : : : Writeln(' Please Input Your Priority Code: ');
    : : : Readln(PriorityCode);
    : : : Writeln(' Please Input Your Hours of Usage: ');
    : : : Readln(UseHours);
    : : :
    : : : End;
    : : :
    : : : Procedure LoopingIt;
    : : :
    : : : Begin
    : : :
    : : : WHILE UserAccount <> 'xxxxx' DO
    : : :
    : : : Begin
    : : :
    : : : IF (UseHours > 15.00) THEN
    : : : HourCharge := (225.00 + (15.00 * UseHours))
    : : :
    : : : ELSE (UseHours > 5.00) AND (UseHours <= 15.00)
    : : : HourCharge := (100.00 + (25.00 * UseHours))
    : : :
    : : : ELSE
    : : : HourCharge := 100.00;
    : : :
    : : : End;
    : : : End;
    : : : End;
    : : :
    : : : BEGIN
    : : :
    : : : CLRSCR;
    : : : Headings;
    : : : GetInfo;
    : : : LoopingIt;
    : : : CalcCharge;
    : : :
    : : : END.
    : : :
    : : :
    : :
    : : Try making UserAccount a text variable. I had this same problem last week, and I converted to a text variable, and everything worked great. :-)
    : :
    : : I didn't even look into the while loop, the error could still be there. Zibadian is a pretty good programmer, go with his suggestion first, and if that doesn't work, try mine. Good Luck.
    : :
    : : Delljohnb
    : :
    : :
    : :
    : Ty for the help, but changing the UserAccount into a text variable, it causes a type mismatch in the While Loop. Any clue why?


    A text variable is used to read/write to text files, he probably meant to use a string variable instead.

    And to answer your question in the other thread about what is wrong with your new CalcCharge function, you should definitely brush up on your IF-THEN-ELSE syntax, because that is definitely one problem with the code. I didn't look over it enough to see if there are others.
  • zibadianzibadian Posts: 6,349Member
    : (Initial Code Was Here)
    : : In addition to Zibadian's comments, I would like to point out that there is a call to "CalcCharge" which doesn't appear to exist.
    : :
    :
    : Alright, I changed some things, but am getting an error compiling using a procedure in the loop. I believe it is the CalcCharge procedure that contains the error. Please let me know how to fix it?
    :
    : PROGRAM Charges;
    : USES CRT;
    :
    : VAR
    :
    : UserAccount : String;
    : PriorityCode, NumberCustomer : Integer;
    : UseHours, HourCharge, AveCharge, PriorityCharge, TotalCharge : Real;
    :
    : Procedure Headings;
    :
    : Begin
    :
    : Writeln(' Apex Computer Service');
    : Writeln;
    : Writeln(' Account Charge');
    : Writeln(' --------- --------');
    :
    : End;
    :
    : Procedure GetInfo;
    :
    : Begin
    :
    : Writeln(' Please Input Your User Account Number: ');
    : Readln(UserAccount);
    : Writeln(' Please Input Your Priority Code: ');
    : Readln(PriorityCode);
    : Writeln(' Please Input Your Hours of Usage: ');
    : Readln(UseHours);
    :
    : End;
    :
    : Procedure LoopingIt;
    :
    : Begin
    :
    : WHILE UserAccount <> 'xxxxx' DO
    :
    : Begin
    :
    : Procedure CalcCharge;
    :
    : Begin
    :
    : IF (UseHours > 15.00) THEN
    : HourCharge := (225.00 + (15.00 * UseHours));
    :
    : ELSE (UseHours > 5.00) AND (UseHours <= 15.00)
    : HourCharge := (100.00 + (25.00 * UseHours));
    :
    : ELSE
    : HourCharge := 100.00;
    :
    : IF PriorityCode = 0 THEN
    : TotalCharge := HourCharge
    :
    : ELSE
    : PriorityCode = 1 THEN
    : TotalCharge := (HourCharge + 50);
    :
    : ELSE
    : PriorityCode = 2 THEN
    : TotalCharge := (HourCharge + 100);
    :
    : End;
    :
    :
    : Procedure ShowData;
    :
    : Begin
    :
    : Writeln(Headings);
    : Writeln(TotalCharge);
    :
    : End;
    :
    : GetInfo;
    : End;
    :
    : BEGIN
    :
    : CLRSCR;
    : Headings;
    : GetInfo;
    : LoopingIt;
    : CalcCharge;
    : ShowData;
    :
    : END.
    :
    :
    The main problem with this code is, that you try to declare a procedure within the execution of another procedure. I know of absolutely no language, which allows that.
    You need to move the CalcCharge() and ShowData() procedure declarations out of the procedure LoopingIt(). Secondly in Pascal you never place a semicolon before an else, because the if-then-else statement is compiled as being a single Pascal statement.
  • FyreAndIce83FyreAndIce83 Posts: 13Member
    First off, I want to thank you all for all your help, I am certainly grateful to you all. Anyway, the good news, I got rid of the nasty errors. Now all I need to do is get the infinite loop to stop and get the results I'd like. How is that achieved in this situation? Code follows:

    VAR

    UserAccount : String[5];
    PriorityCode, NumberCustomer : Integer;
    UseHours, HourCharge, AveCharge, PriorityCharge, TotalCharge : Real;

    Procedure Headings;

    Begin

    Writeln(' Apex Computer Service');
    Writeln;
    Writeln(' Account Charge');
    Writeln(' --------- --------');

    End;

    Procedure GetInfo;

    Begin

    Writeln(' Please Input Your User Account Number: ');
    Readln(UserAccount);
    Writeln(' Please Input Your Priority Code: ');
    Readln(PriorityCode);
    Writeln(' Please Input Your Hours of Usage: ');
    Readln(UseHours);

    End;

    Procedure LoopingIt;

    Begin

    WHILE UserAccount <> 'xxxxx' DO

    Begin


    {Calculating of Charges Begins Here}

    IF (UseHours > 15.00) THEN
    HourCharge := (225.00 + (15.00 * UseHours));

    IF (UseHours > 5.00) AND (UseHours <= 15.00) THEN
    HourCharge := (100.00 + (25.00 * UseHours));

    IF (UseHours <= 5.00) THEN
    HourCharge := 100.00;

    IF PriorityCode = 0 THEN
    TotalCharge := HourCharge;

    IF
    PriorityCode = 1 THEN
    TotalCharge := (HourCharge + 50);

    IF
    PriorityCode = 2 THEN
    TotalCharge := (HourCharge + 100);

    End;


    { Data Output Begins Here}

    Begin

    Writeln(TotalCharge);

    End;

    GetInfo;
    End;

    BEGIN

    CLRSCR;
    GetInfo;
    LoopingIt;
    Headings;

    END.

  • zibadianzibadian Posts: 6,349Member
    : First off, I want to thank you all for all your help, I am certainly grateful to you all. Anyway, the good news, I got rid of the nasty errors. Now all I need to do is get the infinite loop to stop and get the results I'd like. How is that achieved in this situation? Code follows:
    :
    : VAR
    :
    : UserAccount : String[5];
    : PriorityCode, NumberCustomer : Integer;
    : UseHours, HourCharge, AveCharge, PriorityCharge, TotalCharge : Real;
    :
    : Procedure Headings;
    :
    : Begin
    :
    : Writeln(' Apex Computer Service');
    : Writeln;
    : Writeln(' Account Charge');
    : Writeln(' --------- --------');
    :
    : End;
    :
    : Procedure GetInfo;
    :
    : Begin
    :
    : Writeln(' Please Input Your User Account Number: ');
    : Readln(UserAccount);
    : Writeln(' Please Input Your Priority Code: ');
    : Readln(PriorityCode);
    : Writeln(' Please Input Your Hours of Usage: ');
    : Readln(UseHours);
    :
    : End;
    :
    : Procedure LoopingIt;
    :
    : Begin
    :
    : WHILE UserAccount <> 'xxxxx' DO
    :
    : Begin
    :
    :
    : {Calculating of Charges Begins Here}
    :
    : IF (UseHours > 15.00) THEN
    : HourCharge := (225.00 + (15.00 * UseHours));
    :
    : IF (UseHours > 5.00) AND (UseHours <= 15.00) THEN
    : HourCharge := (100.00 + (25.00 * UseHours));
    :
    : IF (UseHours <= 5.00) THEN
    : HourCharge := 100.00;
    :
    : IF PriorityCode = 0 THEN
    : TotalCharge := HourCharge;
    :
    : IF
    : PriorityCode = 1 THEN
    : TotalCharge := (HourCharge + 50);
    :
    : IF
    : PriorityCode = 2 THEN
    : TotalCharge := (HourCharge + 100);
    :
    : End;
    :
    :
    : { Data Output Begins Here}
    :
    : Begin
    :
    : Writeln(TotalCharge);
    :
    : End;
    :
    : [red] GetInfo;[/red]
    : End;
    :
    : BEGIN
    :
    : CLRSCR;
    : GetInfo;
    : LoopingIt;
    : Headings;
    :
    : END.
    :
    :
    You are very close with the solution. You just need to move the call to GetInfo (marked in red) up one line, right after the writeln() line.
  • FyreAndIce83FyreAndIce83 Posts: 13Member
    : : First off, I want to thank you all for all your help, I am certainly grateful to you all. Anyway, the good news, I got rid of the nasty errors. Now all I need to do is get the infinite loop to stop and get the results I'd like. How is that achieved in this situation? Code follows:
    : :
    : : VAR
    : :
    : : UserAccount : String[5];
    : : PriorityCode, NumberCustomer : Integer;
    : : UseHours, HourCharge, AveCharge, PriorityCharge, TotalCharge : Real;
    : :
    : : Procedure Headings;
    : :
    : : Begin
    : :
    : : Writeln(' Apex Computer Service');
    : : Writeln;
    : : Writeln(' Account Charge');
    : : Writeln(' --------- --------');
    : :
    : : End;
    : :
    : : Procedure GetInfo;
    : :
    : : Begin
    : :
    : : Writeln(' Please Input Your User Account Number: ');
    : : Readln(UserAccount);
    : : Writeln(' Please Input Your Priority Code: ');
    : : Readln(PriorityCode);
    : : Writeln(' Please Input Your Hours of Usage: ');
    : : Readln(UseHours);
    : :
    : : End;
    : :
    : : Procedure LoopingIt;
    : :
    : : Begin
    : :
    : : WHILE UserAccount <> 'xxxxx' DO
    : :
    : : Begin
    : :
    : :
    : : {Calculating of Charges Begins Here}
    : :
    : : IF (UseHours > 15.00) THEN
    : : HourCharge := (225.00 + (15.00 * UseHours));
    : :
    : : IF (UseHours > 5.00) AND (UseHours <= 15.00) THEN
    : : HourCharge := (100.00 + (25.00 * UseHours));
    : :
    : : IF (UseHours <= 5.00) THEN
    : : HourCharge := 100.00;
    : :
    : : IF PriorityCode = 0 THEN
    : : TotalCharge := HourCharge;
    : :
    : : IF
    : : PriorityCode = 1 THEN
    : : TotalCharge := (HourCharge + 50);
    : :
    : : IF
    : : PriorityCode = 2 THEN
    : : TotalCharge := (HourCharge + 100);
    : :
    : : End;
    : :
    : :
    : : { Data Output Begins Here}
    : :
    : : Begin
    : :
    : : Writeln(TotalCharge);
    : :
    : : End;
    : :
    : : [red] GetInfo;[/red]
    : : End;
    : :
    : : BEGIN
    : :
    : : CLRSCR;
    : : GetInfo;
    : : LoopingIt;
    : : Headings;
    : :
    : : END.
    : :
    : :
    : You are very close with the solution. You just need to move the call to GetInfo (marked in red) up one line, right after the writeln() line.
    :

    Okay, recommended changes were made. How do I get out of the infinite loop though?
«1
Sign In or Register to comment.