I am stuck in this question. I don't know how to proceed
The question ?
If A=1 , B=2 ,C=3 , D=4, E=5 ........................................... then print the sum of the user entered word ..
( if the user enters ABC, then the output must come :" 6 " .. (because 1 + 2 + 3 = 6)
DIM WORD AS STRING
DIM SUM AS INTEGER
INPUT "Enter a word: ", WORD$
SUM = 0
FOR N=1 to LEN(WORD$)
SUM = SUM + ASC(MID$(WORD$,N,1))
NEXT N
PRINT "Word value: ",SUM
google is your friend. I have never used qbasic, but in about five minutes I found enough code online to do the task.
thank you. can u tell me how you actually found it ?
I did google searches for
qbasic input
to find how to do input and print
qbasic math
to see how math was done. It also showed the DIM statements and a FOR loop
qbasic strings
to find string functions like Val and CHR and ASC
wap to produce report cord of three students
To solve this question, you need to find the sum of the values corresponding to each letter in the word entered by the user. Here's an explanation of how to proceed:
1. Prompt the user to enter a word or sequence of letters.
2. Retrieve and store the word entered by the user.
3. Initialize a variable, let's call it "sum," to keep track of the cumulative value of the letters in the word.
4. Iterate through each character in the word.
5. For each character, calculate its corresponding value based on the given values (A = 1, B = 2, C = 3, etc.). To do this, subtract the ASCII value of 'A' (65) from the ASCII value of the character and add 1.
6. Add the calculated value to the "sum" variable.
7. Repeat steps 4-6 for each character in the word.
8. Print the value of the "sum" variable.
By following these steps, you should be able to get the correct sum of the user-entered word.