Thursday, February 23, 2012

Q Basic question for comp pro. class?

anyone wanna program this:



im a beginner Q Basic person, and all i know in it is the basic , Basic strings, and basic looping



so some one want to program this one easily! or tell me a few guiding steps to do it. or just how to start it.



"a list of numbers is to be typed at the Keyboard. after each number is typed, the program should cause two values to be displayed: a count of how many numbers have been typed and the average of all numbers entered to that time. the program should halt when the user types 0.



thnx for all the help!

Q Basic question for comp pro. class?
Here's the code,

1. declare all the variables, we got count, average(avg), to come up with average you need total(tot), and n as container variable to receive number from user

2. since you didn't say the number of loops so it is an infinite loop, so use While, until a condition arise which is Flg not 0, like Flg is set to 1

3. use INPUT to get number from user and store it in n

4. increase count by 1 in each loop

5. use an IF statement to see if n is 0 if yes, Flg = 1 i.e. get out of loop and end

6. if no, n is not 0, add n to tot, and divide tot by count to get average, print out the 2 number tot and avg



DIM count AS INTEGER

DIM tot AS DOUBLE

DIM avg AS DOUBLE

DIM n AS DOUBLE

CLS



WHILE (Flg = 0)

INPUT "Give me a number"; n

count = count + 1

IF n = 0 THEN

PRINT "Try again next time. Bye!"

Flg = 1

ELSEIF n %26lt;%26gt; 0 THEN

tot = tot + n

avg = tot / count

PRINT "Count:"; count; " Average:"; avg

END IF

WEND

Please contact for more details

No comments:

Post a Comment