Jiskha Homework Help
SATURDAY
November 21, 2009
SCHOOL SUBJECTS
- Art
- Business
- Computers
- English
- Foreign Languages
- Health
- Home Economics
- Math
- Music
- Physical Education
- Science
- Social Studies
GRADE LEVELS
- Preschool
- Kindergarten
- Elementary School
- 1st Grade
- 2nd Grade
- 3rd Grade
- 4th Grade
- 5th Grade
- 6th Grade
- 7th Grade
- 8th Grade
- High School
- 9th Grade
- 10th Grade
- 11th Grade
- 12th Grade
- College
- Adult Education
Post a New Question | Current Questions | Chat With Live Tutors

Homework Help Forum: programming

Posted by cl on Wednesday, September 2, 2009 at 1:19am.

I am supposed to modify this program so it begins by asking the user for the number of values. The program then uses a loop to read the specified number of values and then display their average. program is below that i worked on in class. I been working on this all day and done tired everything anybody can tell me what im missing or what i left out not sure what to do next?

dim value as integer
dim average as integer
dim total as integer
for x as integer = 1 to 5
console.write("please type a value:")
value = Console.Readline()
total = total + value
next
console.write("The average is")
average = total / 5
console.write(average)

  • programming - MathMate, Wednesday, September 2, 2009 at 8:33am

    The program has certain issues:
    1. there should be a variable outside of the for loop to register the number of values, which is NOT fixed at 5.
    Let's say this is stored as "num".
    2. value, total and average should be decimal numbers (and not integers), because the average of 2 and 3 is 2.5.
    3. The temporary variable x should preferably be declared like other variables.
    4. The rest of it seems OK. Make the appropriate modifications, compile, and run as required.



    DIM NUM AS INTEGER
    DIM X AS INTEGER
    dim value as DECIMAL
    dim average as DECIMAL
    dim total as DECIMAL
    CONSOLE.WRITE("How many values:")
    NUM = CONSOLE.READLINE()
    for x = 1 to NUM
    console.write("please type a value:")
    value = Console.Readline()
    total = total + value
    next
    console.write("The average is")
    average = total / NUM
    console.write(average)

Answer this Question

First Name:
School Subject:
Answer:

SEARCH

COMMUNITY
FEATURES
- Live Tutors
- Net Riddle
- Reference
- Search