Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

# Thread: calculating the average of given numbers.

1. ## calculating the average of given numbers.

am trying to calculate the average and median of numbers keyed in by the user. written the code, can anyone please help me with the compilation errors. am using a bloodshed dev c++ kind of compiler.

/*Lesen Sie beliebig viele (max. 50) Zahlen (Abschluss mit dem Wert 0) ein, speichern Sie diese in einem Feld und geben Sie Mittelwert, Median und die Standardabweichung der Zahlen aus. (Bei der Ermittlung der Medians können Sie davon ausgehen, dass die Zahlen schon sortiert sind, vom Benutzer
also entweder in aufsteigender oder in fallender Reihenfolge eingegeben werden.)*/

#include<iostream>
#include<cmath>
using namespace std;

int main(){
int arr[50];
int zahl;
int sum = 0;
int average;
int j;
int median;

cout<<"please key integers not exeeding 50 and not a zero: ";
cin>> zahl;
int i;
for(;zahl!=0;i++){ // i is the actual count of given numbers i.e normally frm 1
arr[i] = zahl; //storage of given number
}
for(int k=0;k < i;k++){ // k is the storage of numbers in array
sum = sum + arr[k]; //sum = sum + the number stored at index 0 and the k++ helps move nxt position
average = sum/i; // divide by i the actual count
cout<<"The avearge/mittelwert = "<<average;
}

j=i/2;//calculating the median
if (i%2!=0){
median = arr[j];

cout<<"median is: "<<median;

else

median = (arr[j]+ arr[j-1])/2; // for even numbers
cout<<"median is: "<<median;
}
return 0;
}

thanks.

• what errors? you must provide errors message.

as far as I see you are missing some {,} in code:
Code:
```j=i/2;//calculating the median
if (i%2!=0){
median = arr[j];

cout<<"median is: "<<median;

`}`else`{ `

median = (arr[j]+ arr[j-1])/2; // for even numbers
cout<<"median is: "<<median;
`}`
}
return 0;
}```
Edit: and please put your code between [ code] and [ /code], without spaces inside

regards

•

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•