c++ - Getting error message "Not declared in scope" -


this question has answer here:

i working on c++ project , while compiling, receiving error messages:

error: mean not declared in scope
error: standard_dev not declared in scope

my code

#include <iostream> #include <iomanip> #include <fstream> #include <cmath> #include <string>  using namespace std;  int main() {     int n(0);     char filename[100];     double m, stdev;     string temp;      double next;     int count = 0;     cout << "enter name of file: ";     cin >> filename;      ifstream myfile;     myfile.open(filename);     while (myfile >> next)     {         count++;     }     n = count;     double* mydata;     mydata = new double[n];      (int = 0; < n; i++)     {         myfile >> mydata[i];     }     m = mean(mydata, n);     stdev = standard_dev(mydata, m, n);     cout << "the standard deviation is:" << stdev << endl;      myfile.close();     delete[] mydata;     return 0; }  double mean(double* mydata, double n) {     double sum(0), m;     (int = 0; < n; i++)     {         sum += mydata[i];     }     m = (sum / (double) n);     return (m); } double standard_dev(double* mydata, double m, int n) {     double* mydata2 = new double[n];     (int = 0; < n; i++)     {         mydata2[i] = pow((mydata[i] - m), 2);     }     double sum(0), s, x;     (int = 0; < n; i++)     {         sum += mydata2[i];     }     x = sum / n;     s = sqrt(x);     return (s); } 

those functions have not been seen yet when try use them; compiler doesn't know leads error. either move them before main() or prototype them, such as:

double mean(double * mydata, double n); double standard_dev(double * mydata, double m, int n); int main() {     ... 

this give compiler expectations symbols, when sees them in use knows them.


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -