Start Raptor, and create a Raptor program as follows. The program will ask the user for a string of digits. Then it will convert each digit in the string to its numeric value and add the values. Right-click the Start symbol and select Comment. Type comment lines for the Author, Date, and Description, then click Done. Do this for all Raptor programs. You are adding numbers, so create an accumulator variable and initialize it to 0. NOTE: Raptor will interpret a string of digits as a number, unless you include a character in it. So, by putting an X at the end of the string of digits, Raptor will use it like a string of characters. Then, we will just ignore the last character when we are converting the digits to numbers. Prompt the user to enter a string of digits followed by an X, and store it in a variable, such as numberString. Set a variable to the length of the string minus 1 (to ignore the X). You can do this by setting the variable len to length_of(numberString) – 1. Set an index variable to 1, and create a loop that exits when index > len. Inside the loop, you need to convert each digit to its numeric value. Look at the ASCII table in Appendix A. The digit ‘0’ has an ASCII value of 48, so if you subtract 48 from its ASCII value, you get its numeric value. The digit ‘1’ is ASCII 49, etc., so you can subtract 48 from the ASCII value of any digit to get its numeric value. There is a function called to_ascii() that returns the ASCII value of a single character. Extract the single character from the string by setting a variable called digit to numberString[index]. Remember that a string can be used as an array of characters. Use a selection to determine if the character is really a digit (if to_ascii(digit) >= 48 and to_ascii(digit)

Leave a Reply

Your email address will not be published. Required fields are marked *