PDA

View Full Version : Forums member in need


Jason 16
05-19-2009, 07:56 PM
mis type no s on forums
I was given this and told to find the errors and I cant for the life of me I know its a small one and its in pascal. could you guys help me out. Its a simple program that takes number grades and make them letter grades I just dont know where the last error is Ive all ready found 4 of the five.:unsure-1:

Program LetterGradeConversion;

var {Global Variable List}
Grade:Real;
LetterGrade:Char;

{-----------GetNumerialcGrade-------------------------}

procedure GetNumberGrade(var grade:real);

begin
write('Please enter a grade:');
readln(Grade);
end;

{------------CalculateLetterGrade--------------------}

Procedure CalculateLetterGrade (var Grade:real; letter Grade:char);

begin
if Grade>= 92.5 then letter grade:='A';
If(Grade >=83.5) and (Grade<92.5) then Lettergrade:='B';
If(Grade >=71.5) and (Grade<83.5) then Lettergrade:='C';
If(Grade >=59.5) and (Grade<71.5) then Lettergrade:='D';
if Grade<= 59.5 then letter grade:='F';
end;

{-------EchoDataAndPrintConversionResults---------------}

Procedure EchoDataAndPrintconversionresults(var LetterGrade:char);

begin
writeln('Agrade of ',Grade:0:0,'is a ', lettergrade);
end;

{-----------------Main------------------}

begin
GetNumberGrade(Grade);
CalculateLetterGrade(Grade,LetterGrade);
EchoDataAndPrintConversionResults(LetterGrade);
end.

Jason 16
05-19-2009, 08:01 PM
every thing works but the letter grade printing

VCURamFan
05-19-2009, 08:24 PM
I'm of no help to you. Sorry.

Llamafighter
05-19-2009, 08:40 PM
mis type no s on forums
I was given this and told to find the errors and I cant for the life of me I know its a small one and its in pascal. could you guys help me out. Its a simple program that takes number grades and make them letter grades I just dont know where the last error is Ive all ready found 4 of the five.:unsure-1:

Program LetterGradeConversion;

var {Global Variable List}
Grade:Real;
LetterGrade:Char;

{-----------GetNumerialcGrade-------------------------}

procedure GetNumberGrade(var grade:real);

begin
write('Please enter a grade:');
readln(Grade);
end;

{------------CalculateLetterGrade--------------------}

Procedure CalculateLetterGrade (var Grade:real; letter Grade:char);

begin
if Grade>= 92.5 then letter grade:='A';
If(Grade >=83.5) and (Grade<92.5) then Lettergrade:='B';
If(Grade >=71.5) and (Grade<83.5) then Lettergrade:='C';
If(Grade >=59.5) and (Grade<71.5) then Lettergrade:='D';
if Grade<= 59.5 then letter grade:='F';
end;

{-------EchoDataAndPrintConversionResults---------------}

Procedure EchoDataAndPrintconversionresults(var LetterGrade:char);

begin
writeln('Agrade of ',Grade:0:0,'is a ', lettergrade);
end;

{-----------------Main------------------}

begin
Get Numeric Grade(Grade);
CalculateLetterGrade(Grade,LetterGrade);
EchoDataAndPrintConversionResults(LetterGrade);
end.
If(Grade >=59.5) and (Grade<71.5) then Lettergrade:='D';
if Grade<= 59.5 then letter grade:='F';
end;
they're both occupying 59.5

is that what you meant?

Jason 16
05-19-2009, 08:50 PM
If(Grade >=59.5) and (Grade<71.5) then Lettergrade:='D';
if Grade<= 59.5 then letter grade:='F';
end;
they're both occupying 59.5

is that what you meant?
yea I need to get ridd of the = on the grade <=59.5

if you see any thing else please comment I cant cheak if its right till school

County Mike
05-19-2009, 08:57 PM
Procedure CalculateLetterGrade (var Grade:real; letter Grade:char);

begin
if Grade>= 92.5 then letter grade:='A';
If(Grade >=83.5) and (Grade<92.5) then Lettergrade:='B';
If(Grade >=71.5) and (Grade<83.5) then Lettergrade:='C';
If(Grade >=59.5) and (Grade<71.5) then Lettergrade:='D';
if Grade<= 59.5 then letter grade:='F';
end;

{-------EchoDataAndPrintConversionResults---------------}

Procedure EchoDataAndPrintconversionresults(var LetterGrade:char);

begin
writeln('Agrade of ',Grade:0:0,'is a ', lettergrade);
end;

{-----------------Main------------------}

begin
Get Numeric Grade(Grade);
CalculateLetterGrade(Grade,LetterGrade);
EchoDataAndPrintConversionResults(LetterGrade);
end.

Besides extra or needed spaces throughout, I mostly just see where the code is inefficient. I'd do it more like this:

Lettergrade := 'F';
If Grade >= 59.5 Then Lettergrade := 'D';
If Grade >= 71.5 Then Lettergrade := 'C';
If Grade >= 83.5 Then Lettergrade := 'B';
If Grade >= 92.5 Then Lettergrade := 'A';

You could also do this in reverse starting with assigning Lettergrade to 'A' and work down using if-then-else.

or use a Case statement but I forget how to do that in Pascal.

Also, you name a procedure 'GetNumberGrade' but call it with 'GetNumericGrade'.

Josh
05-20-2009, 04:55 AM
mis type no s on forums
I was given this and told to find the errors and I cant for the life of me I know its a small one and its in pascal. could you guys help me out. Its a simple program that takes number grades and make them letter grades I just dont know where the last error is Ive all ready found 4 of the five.:unsure-1:

Program LetterGradeConversion;

var {Global Variable List}
Grade:Real;
LetterGrade:Char;

{-----------GetNumerialcGrade-------------------------}

procedure GetNumberGrade(var grade:real);

begin
write('Please enter a grade:');
readln(Grade);
end;

{------------CalculateLetterGrade--------------------}

Procedure CalculateLetterGrade (var Grade:real; letter Grade:char);

begin
if Grade>= 92.5 then letter grade:='A';
If(Grade >=83.5) and (Grade<92.5) then Lettergrade:='B';
If(Grade >=71.5) and (Grade<83.5) then Lettergrade:='C';
If(Grade >=59.5) and (Grade<71.5) then Lettergrade:='D';
if Grade<= 59.5 then letter grade:='F';
end;

{-------EchoDataAndPrintConversionResults---------------}

Procedure EchoDataAndPrintconversionresults(var LetterGrade:char);

begin
writeln('Agrade of ',Grade:0:0,'is a ', lettergrade);
end;

{-----------------Main------------------}

begin
GetNumberGrade(Grade);
CalculateLetterGrade(Grade,LetterGrade);
EchoDataAndPrintConversionResults(LetterGrade);
end.
It seems that you are channeling messages from alien civilizations. Hope that was helpful.

Jason 16
05-20-2009, 08:59 PM
It seems that you are channeling messages from alien civilizations. Hope that was helpful.
what do you mean its plain english :laugh:

County Mike
05-21-2009, 03:15 AM
So what's the verdict? Did you get it working correctly?

Jason 16
05-21-2009, 09:11 PM
I got it working there were little stupid mistakes one was a random . in the code