Computer Science Canada

ASCII help

Author:  lei4848 [ Thu Mar 23, 2006 12:45 am ]
Post subject:  ASCII help

i am suppose to create a program where the user input the character "23" and the out put would be 23...i need serious help.

var car : char
var num : int
var cars : char
var nums : int

loop
get car
num:= ord(car)-48
nums:= ord(cars)
put num, nums
end loop

Author:  Andy [ Thu Mar 23, 2006 1:46 am ]
Post subject: 

code:

var ch : string (1)
getch(ch)
put ord(ch)

Author:  chrispminis [ Thu Mar 23, 2006 8:18 pm ]
Post subject: 

That's not what he means Andy.

You could do it;

code:
var : str
get str
put str


But I think you mean something like this...


code:
var str : string
var number : int := 0

get str
for i : 1 .. length (str)
number *=  10
number += (ord (str (i)) - 48)
end for
put number
put number * 2


Not sure if the above works, but it should.

Author:  lei4848 [ Thu Mar 23, 2006 11:42 pm ]
Post subject: 

thanks allot!!!

Author:  Andy [ Thu Mar 23, 2006 11:45 pm ]
Post subject: 

oh, he said character 23... i guess he menant characters 2 and 3


: