What does it mean if my program compiles but when I run it it says foating point exception (core dumped). Thanks for your help!!

## All 5 Replies

Paying attention to error codes or phrases may give you something to google. Posting your code will also be helpful if you need help debugging it. (And don't forget the code tags!)

yeah try to do do

Here is my code. The program should find the standard deviation of a list of numbers entered in an array.

``````#include <iostream>
#include <cmath>

void input(double dev[], int& count);
double average(const double dev[], int size);
double calculation(const double dev[], double totalAverage, int size);

int main()
{
const int MAX = 100;
double dev[MAX], totalAverage, deviation, total;
int size, count;

input(dev, size);
totalAverage = average(dev, size);
deviation = sqrt (calculation(dev, totalAverage, int size));
cout << deviation << endl;
}

void input(double dev[], int& count)
{
const int SENTINEL = -1;
int number;

cout << "Enter a list of numbers and -1 to end the list" << endl;
count = 0;
cin >> number;
while(number != SENTINEL)
{
dev[count] = number;
count++;
cin >> number;
}
}

double average(const double dev[], int size)
{
double total = 0;
for( int i = 0; i < size; i++)
{
total = (total + dev[i]) / size;
}
}

double calculation(const double dev[], double totalAverage, int size)
{
double standard;
for(int i = 0; i < size; i++)
{
standard = ((dev[i] - totalAverage) * (dev[i] - totalAverage)) / size;
}
return standard;
}``````
``deviation = sqrt (calculation(dev, totalAverage, int size));``

This is a syntax error, it should be:

``deviation = sqrt (calculation(dev, totalAverage, size));``

You should have this after your includes (at a minimum).

``using namespace std;``

My output

Enter a list of numbers and -1 to end the list
5
6
1
2
9
0
17
-1
5.49721

What compiler/OS?

I added the using namespace std; and took the int off and I still get a floating point exception(core dumped).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.