0
votes

Here are a couple of lines from my input file:

35, 35, 21, 0.6, 25, 2.8, 3.4, 13, 8.7, 0.43, 0.81, 400, 480
40, 40, 24, 0.6, 26, 2.9, 3.8, 14, 9.4, 0.47, 0.88, 420, 500

And this is the code snippet where I am trying to get my input file read:

cout<< "Please enter 1 if the timber is soft or 2 if the timber is hard."<<endl;
cin>> classs;

if (classs == 1)
{ 
    ifstream soft;
    soft.open ("Softwood.txt");

cout <<"Please enter the strength class of the timber, excluding the letter." <<endl;
cin >> type;

double a [12][13];

int i, j;

for (i=0; i<12; i++)
{
    for (int j=0; j<13; j++)
        soft>>a[i][j];
}

int m=0;

while(a[m][0]!= type)
{
    m++;
}

bendingStrength = a[m][1];
tensionParallel = a[m][2];
tensionPerpindicular = a[m][3];
compressionParallel = a[m][4];
compressionPerpindicular = a[m][5];
shearStrength = a[m][6];
elasticityParallel = a[m][7];
elasticityParallelFive = a[m][8];
elasticityPerpindicular = a[m][9];
shearModulus = a[m][10];
density = a[m][11];
meanDensity = a[m][12];

For some reason it just stops at this point while(a[m][0] = type) and I have no idea why. Any help would be much appreciated! Thanks!

1

1 Answers

0
votes

If you don't enter a matching value of type, the it will give you an error as value of m will exceed the number of rows in the array. Try using following code:

while(a[m][0]!= type && m<12)
{
    m++;
}