Pascal Help ? 6 errors that I do not know how to fix

Status
Not open for further replies.

TacticalMaestro

Reputable
Mar 19, 2014
7
0
4,510
Program TypeofCreditCard;
Var
AppliName: array[1..99] of String;
SSnum: array[1..99] of Integer;
GSal: array[1..99] of Integer;
TSalD: array[1..99] of Integer;

Name, CC : String;
Rep,Exp, GS,NS,Sum,TSD , YS,SSN,i,C_Amt,PofIncome : integer ;

Begin
Writeln ( 'Enter applicants who applied for a type of credit card');
Readln (Rep,Exp,GS,YS,NS,Sum,TSD,SSN,CC,PofInco... ;

While ( Name <> ' Stop ' ) do
Begin
NS:= GS-TSD ;
Sum:= Exp + Rep ;
PofIncome:=(NS * 0.45);
Begin
If ( GS >4000) AND ( CC = 'Bronze Card' ) then
YS:= GS * 12 ;
C_Amt := YS * 0.25;
i:= i + 1;
AppliName := Name;
SSNum := SSN ;
GSal [ i]:= GS ;
TSalD := TSD ;
End ;
Begin
If (GS >= 7500) AND [CC= 'Gold Card'] then
YS:= GS * 12 ;
C_Amt:= YS * 0.3;
i:= i + 1 ;
AppliName := Name;
SSnum:=SSN;
GSal:=GS;
TSalD:=TSD;
End;
Begin
If (GS>=10,000) AND ( CC = ' Platinum Card') then
YS := GS * 12;
C_Amt: = YS * 0.4;
i:= i + 1;
A ppliName := Name;
SSNum := SSN;
GSal :=GS;
TSalD := TSD;


End if
End if
End if
End While
End.



The five errors are :
1. Error:Incompatible types: got "Boolean" expected "LongInt" - For this line : If (GS >= 7500) AND [CC= 'Gold Card'] then

2.Error:Incompatible types: got " Set of Boolean" expected " LongInt" - for the same line (If (GS >= 7500) AND [CC= 'Gold Card'] then )

3.Error:Incompatible types: got "single" expected "smallint" - for C_Amt := YS * 0.25 ; in Bronze Card

4.Error:Incompatible types: got "extended" expected "smallint" for C_Amt := YS * 0.3; in Gold Card

5.Fatal:syntax error , ")" expected but "," found - (If GS >= 10000) AND [CC= 'Platinum'] then )

Thanks for any help. I know my program is by no means perfect because I am awful at Pascal and desperately need help on fixing these things. So I am open to anything that will get this program running in Pascal. Thanks.
 
Solution
1 & 2. Square brackets should be parenthesis:
This: If (GS >= 7500) AND [CC= 'Gold Card'] then
Should be this: If (GS >= 7500) AND (CC= 'Gold Card') then

3 & 4:
You have C_Amt and YS declared as integer yet you are multiplying by a real.

5: there should be no parenthesis at the end of that line.

Your code is hard to read. try indenting where needed. if it was already indented before you copied/pasted, then use the [code ] bbcodes in order to keep the formatting.
1 & 2. Square brackets should be parenthesis:
This: If (GS >= 7500) AND [CC= 'Gold Card'] then
Should be this: If (GS >= 7500) AND (CC= 'Gold Card') then

3 & 4:
You have C_Amt and YS declared as integer yet you are multiplying by a real.

5: there should be no parenthesis at the end of that line.

Your code is hard to read. try indenting where needed. if it was already indented before you copied/pasted, then use the [code ] bbcodes in order to keep the formatting.
 
Solution
Well for one thing, the "[" and "]" may not be used in place of parentheses "(" and ")" in boolean expressions to be evaluated. Second, if you want to assign the integer portion of a real number to an integer variable, you need to use a function like TRUNC, as in "integer_var := TRUNC(real_expression);"
 
This is how your program looks when enclosed in [ code ] and [ / code ] tags:
Code:
Program TypeofCreditCard; 
Var 
    AppliName: array[1..99] of String; 
    SSnum: array[1..99] of Integer; 
    GSal: array[1..99] of Integer; 
    TSalD: array[1..99] of Integer; 

    Name, CC : String; 
    Rep,Exp, GS,NS,Sum,TSD , YS,SSN,i,C_Amt,PofIncome : integer ; 

Begin 
    Writeln ( 'Enter applicants who applied for a type of credit card'); 
    Readln (Rep,Exp,GS,YS,NS,Sum,TSD,SSN,CC,PofInco... ; 

    While ( Name <> ' Stop ' ) do 
    Begin 
        NS:= GS-TSD ; 
        Sum:= Exp + Rep ; 
        PofIncome:=(NS * 0.45); 
        Begin 
            If ( GS >4000) AND ( CC = 'Bronze Card' ) then 
                YS:= GS * 12 ; 
            C_Amt := YS * 0.25; 
            i:= i + 1; 
            AppliName := Name; 
            SSNum := SSN ; 
            GSal [ i]:= GS ; 
            TSalD := TSD ; 
        End ; 
        Begin 
            If (GS >= 7500) AND [CC= 'Gold Card'] then 
                YS:= GS * 12 ; 
            C_Amt:= YS * 0.3; 
            i:= i + 1 ; 
            AppliName := Name; 
            SSnum:=SSN; 
            GSal:=GS; 
            TSalD:=TSD; 
        End; 
        Begin 
            If (GS>=10,000) AND ( CC = ' Platinum Card') then 
                YS := GS * 12; 
            C_Amt: = YS * 0.4; 
            i:= i + 1; 
            AppliName := Name; 
            SSNum := SSN; 
            GSal :=GS; 
            TSalD := TSD; 
        End if 
        End if 
        End if 
    End While 
End.
 
(sorry for double-post, it will be easier)...

Appart from the errore already discussed, there are some more:
- there are not "end if" and "end while" operators in Pascal (OK, at least in the popular ones);
- your ReadLn statement probably won't work - string variables will get empty values. Split it on several Write / ReadLn statements
- you have several arrays, but assignment statements are missing [Index] part of the array, e.g. AppliName := Name;
- you are not checking if one will enter more that 100 applicants
 

TacticalMaestro

Reputable
Mar 19, 2014
7
0
4,510
I'm down to 2 errors now and I am pleased but I just really need it to run.
This is the error - Fatal:Syntax Error, ";" expected but "identifier Writeln found - Source of error- Writeln ( 'Enter applicants who applied for a type of credit card');

Is there some sort of documentation about what each error means??I want to learn.
 
The message means exactly what it says. The compiler was expecting to find ";" but instead it found "Writeln". Normally this means the semicolon is missing from the line before the one listed but your program, as you list it, has no statement before that line. Have you added something since?
 

TacticalMaestro

Reputable
Mar 19, 2014
7
0
4,510


I've done nothing but do the changes I've been told to made.
 

TacticalMaestro

Reputable
Mar 19, 2014
7
0
4,510


I inserted that beginning then one more error came up and it said
Fatal syntax error, ";' expected but " BEGIN" found
 
@Tactical - it would be helpful if you mention what compiler you're using, and (when errors happen) - at what line.

On your program:
- Put a "Begin" before first "WriteLn";
- Put "I := 0" before "while" statement
- change "while" to check that I is less than 100
- change internal "If" to check for "Name <> 'Stop'"
- Remove last two "End;" before "End.";

Probably there are more... Change your program, re-post it on PasteBin for further help
 

TacticalMaestro

Reputable
Mar 19, 2014
7
0
4,510
So i followed through and continued to attempt to run the program and eventually after trying to follow and fix every error , I think it started running but i don't understand because its been more than 5 hours now that it has said that the PASCAL file is now running but i can not type anything in the black screen and it can not be closed down.Additionally, because I didn't know it would run after i corrected the last error, this means that I have not saved the most recent version of the PASCAL yet. The problem with that is for my assignment it says " You have to show evidence that your program ran (a print screen after it compiled. Print screen of some data that you entered and a print screen of the output) "

Will it ever run or come off of this screen that it seems to be stuck on?
 
@Tactical - for God's sake, what version of Pascal are you using?
Try pressing <Ctrl>-<Break>, or <Ctrl>-C, to terminate your program. If you have a debugger in your environment, you can try to terminate your program from there as well.

And since we don't know how your program looks now, noone can tell what will come out of it ;)
 
The last version of the program that you listed had an infinite loop in it. You never change the value of "Name" inside the "While" loop. This is why the program keeps running.

As the previous poster said, just break into the program. How you do that depends upon your environment.
 
Status
Not open for further replies.