Pascal Q: How to convert a integer to char?

Status
Not open for further replies.

Fortify

Posts: 28   +0
Wondering how to convert an integer into character.
I want to convert:

Mark: Grade:
91-100 into A
71-90 into B
50-70 into C
25-49 into D
0-24 into E
 
Well it is kind a possible with arrays, but the simplest way to do this is:

program prog_1;

var number:integer;
character:char;

begin

write('Enter the number : ');
readln(number);

if (number>0) and (number<24) then character:='E'
else if (number>25) and (number<49) then character:='D'
else if (number>50) and (number<70) then character:='C'
else if (number>71) and (number<90) then character:='B'
else if (number>91) and (number<100) then character:='A'
else writeln('UNDEFINED!');

writeln(character);
end.

In this way u get what u wanted.
Maybe there is a easier way, but i just cant think about anything simpler than this one.
Sorry for bad english.
 
Status
Not open for further replies.
Back