| | |
runtime errors.
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2008
Posts: 2
Reputation:
Solved Threads: 0
my program has the following errors:
there are primary-expressions 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[j-1])/2; // for even numbers
cout<<"median is: "<<median;
}
return 0;
}
there are primary-expressions 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[j-1])/2; // for even numbers
cout<<"median is: "<<median;
}
return 0;
}
You should check how to use If & Else stantements, you have
This is wrong due to bracket positioning it should be
C++ Syntax (Toggle Plain Text)
if(standarddeviation>0){ cout<<"standardeviation: "<<standarddeviation<<endl; else cout<<"standarddeveiation not valid."; }
C++ Syntax (Toggle Plain Text)
if(standarddeviation>0){ cout<<"standardeviation: "<<standarddeviation<<endl; } else{ cout<<"standarddeveiation not valid."; }
Knowledge is power -- But experience is everything
Look at this loop condition. If it's true it's true forever (not forever: until inevitable crash).
C++ Syntax (Toggle Plain Text)
int i; for (i = 1; zahl != 0; i++) { // Congratulation! It's loop until all core was overwritten... arr[i] = zahl; //storage of given number }
Last edited by ArkM; Nov 9th, 2008 at 4:37 pm.
![]() |
Similar Threads
- Runtime Error -21470024770 (8007007e) (Windows NT / 2000 / XP)
- String maniputlation runtime error (C++)
- Program compiles but has runtime problems (Java)
- Runtime Errors (Web Browsers)
- run time errors when using IE (Web Browsers)
Other Threads in the C++ Forum
- Previous Thread: c++ tutorials
- Next Thread: cannot convert `int*' to `int**'
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer display dll email encryption error file forms fstream function functions game generator getline givemetehcodez graph homeworkhelper iamthwee ifstream image input int java lazy lib loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






