Post a New Question

programming

posted by .

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 -

    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:

Related Questions

More Related Questions

Post a New Question