0

I'm trying to log a few values to a text file, but everytime I do it, it gives me this error:

[Error] 'save' was not declared in this scope

Here's the code:

#include "iostream"
#include "fstream"

using namespace std;
double n1, n2;

int main()
{

    n1 = 1;
    n2 = 2;
    save(n1, n2)

}
int save(double a, double b)
{
    ofstream log;
    log.open("test.txt");
    log << 1 << 2 << "\n";
    log.close();
}

I'm new to C++ and programming in general, please explain in an easy way.

Thanks.

João
  • 67
  • 1
  • 7

1 Answers1

3

Code in main needs to know that such a function exists. It needs either a declaration or a definition above it:

int save(double a, double b);

int main() //...

By the way: you should eschew using global variables. And you're not using the parameters in your save function.

krzaq
  • 16,240
  • 4
  • 46
  • 61