Enjoy an ad free experience by logging in. Not a member yet? Register.

Results 1 to 3 of 3
Thread: runtime errors.

11092008, 05:35 PM #1
 Join Date
 Nov 2008
 Posts
 2
 Thanks
 0
 Thanked 0 Times in 0 Posts
runtime errors.
my program has the following errors:
there are primaryexpressions expected before "else"
the upon commening on the lines with else, i got a mistake like "core dumped" and it couldn't run no more. could anyone please take a minute to go through my programm and kindly let me know where the errors are, if possible suggest on what i should do or correct my code please.
#include<iostream>
#include<cmath>
#include<cstdlib> //memory management
using namespace std;
int main(){
int arr[50];
int zahl;
int sum = 0;
int average;
int j;
int median;
double sum2 = 0;
double deviation;
double sqrdeviation;
double msqrdeviation;
double standarddeviation;
cout<<"please key integers not exeeding 50 and not a zero: ";
cin>> zahl;
int i;
for(i = 1;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 i,e k is the index in array
sum = sum + arr[k]; //sum = to 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;
deviation=arr[k]  average;//calculating the deviation 4rm mean
sqrdeviation = (pow(deviation, 2));//squaring the deviation from mean
sum2 += sqrdeviation;//adding the square from deviation from mean
k++;// moving to the next level
msqrdeviation = sum2/i;// getting mean of squared deviations
standarddeviation = sqrt(msqrdeviation);
if(standarddeviation>0){
cout<<"standardeviation: "<<standarddeviation<<endl;
else
cout<<"standarddeveiation not valid.";
}
}
j=i/2;//calculating the median
if (i%2!=0){
median = arr[j];
cout<<"median is: "<<median<<endl;
else
median = (arr[j]+ arr[j1])/2; // for even numbers
cout<<"median is: "<<median;
}
return 0;
}
11092008, 06:08 PM
#2
 Join Date
 Feb 2003
 Location
 Umeå, Sweden
 Posts
 5,575
 Thanks
 0
 Thanked 83 Times in 74 Posts
>Code:if(...){ ... else ... }Code:if(...){ ... }else{ ... }
liorean <[lio@wg]>
Articles: RegEx evolt wsabstract , Named Arguments
Useful Threads: JavaScript Docs & Refs, FAQ  HTML & CSS Docs, FAQ  XML Doc & Refs
Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards
11092008, 07:13 PM
#3
 Join Date
 Dec 2007
 Posts
 6,682
 Thanks
 436
 Thanked 890 Times in 879 Posts
OP posted twice:
http://www.codingforums.com/showthread.php?t=151873
regards