I want to make a program. I want it to ask how many values there are, and then prompt that many times. I then want those to add up and divide by the number of values. Here is what I have so far but I can't get it to work.

:ClrHome

:Disp "V=Values

:Prompt V

:V->Z

:Repeat A>_V or V /= Z

:A+1->A

:Input B

:B=L1

:List>matr(L1,[A]

:End

:Disp L1/V

Average

Forum
» Projects & Contests / Your Projects
» Average

Summary:

A program to ask how many values, prompt that many times and then disp the mean
Average

Andyrocks_a 06 May 2015 21:37

```
Clrhome
Delvar C
Input "Values:",V
for(A,1,V
Input "Number:",B
B+C→C
End
Disp C/V
```

Or you can use the built in list functions of the calculator to find the average.

*The Silver Phantom welcomes you*

This program can be several ways. From your method, it sounds as if you may want to use a For( loop. This way you can loop the input as many times as you want. Here is some pseudocode:

```
Initialize <sum of values> to zero
Display input information
Request input for how many times you want the loop to be run and store to <number of values>
For(<variable>,1,<number of values>
Request input for all of the values
Add the input and the <sum of values> and store it to <sum of values>
End the For( loop
Display <sum of values> divided by <number of values>
```

Your code looks pretty good except for a few minor details.

Although it seems as if you are trying to store B into L1 with this code:

`B=L1`

you are actually testing the list against B. For example, 3={3,1,2,3} will result in {1,0,0,1}.

To store the value, you would want to use the following:

```
augment(L1,{B}->L1 //This will combine L1 and {B} with B as the last element of the list.
or
B->L1(1+dim(L1 //This will store B into the last position of L1 plus 1. This increases the list by one.
```

Also, L1/V divides each element by V. You would want to use sum(L1)/V

Could you do something like:

```
Input "Numbers:", Str1 //input values as #,#,#,etc...
mean(expr("{"+Str1)) //finds the mean of the values by treating the string as a list
Disp Ans
```

Just to show it works, i wrote and tested it:

Optimized more ;)

```
Input "Numbers:",Str1
Disp mean(expr("{"+Str1
```

/forum/t-1189180/average#post-