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?
"the program should halt when the user types 0." - sounds like a loop to me.
"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" - So you need to read in values, count how many values you have read in and calculate the average.
I can't remember my QBasic syntax so you'll have to write the code yourself. I'm going to assume you know how to count and calculate an average (which is why you need the count).
Your code will do something like this:
sum = 0
avg = 0
count = 0
print 'enter number or 0 to quit'
read num
do while num %26lt;%26gt; 0
increment count
calculate average
display count, average
print 'enter number or 0 to quit'
read num
End Loop
This is a very simple program. If you're having trouble with this, then you need to really read the problem and do some analysis and design prior to writing code. One of the biggest problems beginning programmers have is doing analysis and design prior to coding. If you find yourself saying "what do I do now?" then you haven't done enough analysis.Q Basic question for comp pro. class?
I'm not going to write it for you, but will try to help.
Display a message saying enter a number, 0 to stop.
Start a loop with this message as the last line until you get a zero entered.
Read the number entered, store it in a array that you are counting, display the last two numbers in the array (you do the math) , add a count of numbers entered and also a sum of those numbers
When loop completes, divide the sum by the count of the numbers entered and display the value.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment