runtime errors.

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2008
Posts: 2
Reputation: muya08 is an unknown quantity at this point 
Solved Threads: 0
muya08 muya08 is offline Offline
Newbie Poster

runtime errors.

 
0
  #1
Nov 9th, 2008
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;
}
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 671
Reputation: Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough 
Solved Threads: 113
Freaky_Chris's Avatar
Freaky_Chris Freaky_Chris is offline Offline
Practically a Master Poster

Re: runtime errors.

 
0
  #2
Nov 9th, 2008
You should check how to use If & Else stantements, you have
  1. if(standarddeviation>0){
  2. cout<<"standardeviation: "<<standarddeviation<<endl;
  3. else
  4. cout<<"standarddeveiation not valid.";
  5. }
This is wrong due to bracket positioning it should be

  1. if(standarddeviation>0){
  2. cout<<"standardeviation: "<<standarddeviation<<endl;
  3. }
  4. else{
  5. cout<<"standarddeveiation not valid.";
  6. }
Knowledge is power -- But experience is everything
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 2,001
Reputation: ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of 
Solved Threads: 343
ArkM's Avatar
ArkM ArkM is offline Offline
Postaholic

Re: runtime errors.

 
0
  #3
Nov 9th, 2008
Look at this loop condition. If it's true it's true forever (not forever: until inevitable crash).
  1. int i;
  2. for (i = 1; zahl != 0; i++) { // Congratulation! It's loop until all core was overwritten...
  3. arr[i] = zahl; //storage of given number
  4. }
Last edited by ArkM; Nov 9th, 2008 at 4:37 pm.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC