You are using a version without Ads of this website. Please, consider donating:

### array declaration error

I'm trying to wirte a program that reads a from a input file. On one column of the input file is angle and the other is the coefficient. The program is supposed to let the user input an angle and look for the corresponding coefficient and use both to solve an equation. Also, the program should let the user know the angle range. This is my code so far but it is stating that anglemax, anglemin, coeffmax, ceffmin, "has no storage class or type specifier" when clearly I stated double for all four.

#include <iostream>
#include <fstream>
#include <cmath>

using namespace std;

int main();

{

ifstream tunnel;

tunnel.open("tunnelfile.txt"); //opening file

if(!tunnel.fail())
{
cout << "The file could not be found.";
exit(0);
}
else
{

double flightangle[20], coeff[20];
const int n=20;

while (!tunnel.eof())
{
for (int n =0; n<20; ++n) //initializing array
{
tunnel>>flightangle[n]>>coeff[n]; //setting the values to array
}

double anglemax, anglemin, coeffmax, coeffmin; //stating doubles for flight angle max min and coefficient max, min

anglemax = flightangle[n-1]; //max angle is in array n-1
anglemin = flightangle[n]; //min angle is set to 0
coeffmax = coeff[n-1];
coeffmin = coeff[n];

double input, output;
cout <<"Enter a angle from the range:"<< anglemax << "to:" << anglemin <<endl;
cout <<"Enter the angle: ";

cin >> input;

if(input<anglemax && input > anglemin)
{
output = [coeffmin + (input - anglemin) * (coeffmax -coeffmin)]/(anglemax - anglemin);
cout << "The coefficient of lift is: " << output << endl;
}
else
cout <<"Choose another angle, it is not within range." << endl;
return 0;
}
tunnel.close();
return 0;
}
}

This is my input file "tunnelfile.txt"
-2 -0.182
-4 -0.056
0 0.097
2 0.238
4 0.421
6 0.479
8 0.654
10 0.792
12 0.924
14 1.035
15 1.076
16 1.103
17 1.120
18 1.121
19 1.121
20 1.099
21 1.059
Last edited on
Topic archived. No new replies allowed.