Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C++
#include <iostream>
#include <math.h>
using namespace std;

float calculateSD(float data[]);



	{
	int a[20],i,limit;
	
	cout << "Enter the limit of sample :" << endl;
	
	cin >> limit;
	
	cout << "Enter the sample :" << endl;
	
	for (i = 0; i < limit ; ++i)
	
   	{cin >> data [ i ];}
	
    cout << endl << "Standard Deviation = " << calculateSD(data);

    return 0;
	}

float calculateSD(float data[])
{
    float sum = 0.0, mean, standardDeviation = 0.0;

    int i;

    for(i = 0; i < limit; ++i)
    {
        sum += data[i];
    }

    mean = sum/limit;

    for(i = 0; i < 10; ++i)
        standardDeviation += pow(data[i] - mean, 2);

    return sqrt(standardDeviation / limit);
}


What I have tried:

Can anyone help me with this? I dont understand why it come up with an error. What im trying to do is output a mean of sample, variance and standard deviation from input data. Im suck at this.
Posted
Updated 31-May-21 23:26pm
v2

Quote:
float calculateSD(float data[]); //<--- Spurious semicolon here, remove it



{
 
Share this answer
 
To add to what CPallini says, start by looking at the error message - it tells you exactly where it found the problem:
main.cpp:9:1: error: expected unqualified-id before ‘{’ token
{
^

That says the file name is "main.cpp", the line number it found a problem on is "9", the column was "1" and the "^" is pointing to the character it found a problem with.
So go to that line (most editors support CTRL+G to go directly to a line number) and look at a few line above that for context.
C++
float calculateSD(float data[]);



	{
What's above it? The function declaration.
So think about what might be wrong with the line above that could cause a problem later.
Semicolon terminates a statement - so the spurious one at the end of the function declaration is making it a forward declaration - a definition of the function signature with a promise "to fill in the body later".

It's honestly a lot, lot quicker to think about syntax errors and fix them yourself than it is to ask about them! :D
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900