… is what I want to do. I have the following code:
...
int len = 0;
char c;
bool fp = false;
while (infile.good()) {
c = infile.get();
if (c == '\n') ++len;
else if (c == '.') fp = true;
}
if (fp == true){
float Ai[N];
float *Ao = new float [len];
} else {
int Ai[N];
int *Ao = new int [len];
}
for (int i=0; i<L; ++i){
for (int j=0; j<N; ++j) infile >> Ai[j];
Ao[i] = findmax(Ai);
}
...
It is supposed to make the array out of doubles if a decimal point is detected in the file or, if not, out of integers.
I didn’t check the first loop yet because I didn’t get it to compile:
warning: unused variable ‘Ai’
warning: unused variable ‘Ao’
warning: unused variable ‘Ai’
warning: unused variable ‘Ao’
error: ‘Ai’ was not declared in this scope
error: ‘Ao’ was not declared in this scope
I suppose I have a fundamental problem with how to deal with this task and not just a simple error.
So, what is wrong and how to fix/make it right from the beginning?
Edit:
As commented above, your compiler error comes from Ao and Ai being declared in a different scope than where you are trying to use it.
This is where templates come in real handy.