0

I have this program to take properties from a data file and input them into calculations into the program. this is my code at the moment but it isn't taking any values into it.. any help is appreciated

float woodcharacStrength(){
    myInfile.open ("strength_classes.txt");     //inputs external file that contains characteristic values for forces parallel to grain.

    for (row = 0; row<3; row++)
        for (col = 0; col<18; col++)            //condition to only read certain rows and columns of the input file
        {
myInfile >> arraylocation[row][col];        //used to define each value of the array
        }

switch(woodType){
    case 'A':
    case 'a': ftk = arraylocation[0][0]; fck = arraylocation[1][0];break;
    case 'B':
    case 'b': ftk = arraylocation[0][1]; fck = arraylocation[1][1];break;
    case 'C':
    case 'c': ftk = arraylocation[0][2]; fck = arraylocation[1][2];break;
    case 'D':
    case 'd': ftk = arraylocation[0][3]; fck = arraylocation[1][3];break;
    case 'E':
    case 'e': ftk = arraylocation[0][4]; fck = arraylocation[1][4];break;
    case 'F':
    case 'f': ftk = arraylocation[0][5]; fck = arraylocation[1][5];break;
    case 'G':
    case 'g': ftk = arraylocation[0][6]; fck = arraylocation[1][6];break;
    case 'H':
    case 'h': ftk = arraylocation[0][7]; fck = arraylocation[1][7];break;
    case 'I':
    case 'i': ftk = arraylocation[0][8]; fck = arraylocation[1][8];break;
    case 'J':
    case 'j': ftk = arraylocation[0][9]; fck = arraylocation[1][9];break;
    case 'K':
    case 'k': ftk = arraylocation[0][10]; fck = arraylocation[1][10];break;
    case 'L':
    case 'l': ftk = arraylocation[0][11]; fck = arraylocation[1][11];break;
    case 'M':
    case 'm': ftk = arraylocation[0][12]; fck = arraylocation[1][12];break;
    case 'N':
    case 'n': ftk = arraylocation[0][13]; fck = arraylocation[1][13];break;
    case 'O':
    case 'o': ftk = arraylocation[0][14]; fck = arraylocation[1][14];break;
    case 'P':
    case 'p': ftk = arraylocation[0][15]; fck = arraylocation[1][15];break;
    case 'Q':
    case 'q': ftk = arraylocation[0][16]; fck = arraylocation[1][16];break;
    case 'R':
    case 'r': ftk = arraylocation[0][17]; fck = arraylocation[1][17];break;
}

    cout <<"The ftk value is: "<< ftk<< endl<<"The fck value is: "<< fck<<endl;

    return ftk;
    return fck;

    myInfile.close();
}
3
  • The program flow ends in the first return. Place the file close before the return. Also, you're not doing anything with the switch. Commented Dec 11, 2013 at 0:45
  • Sorry im new to c++ i dont really understand.. ill post more of the code up would be grateful for any comments Commented Dec 11, 2013 at 0:50
  • You have two return statements in a row. Execution comes to the first return statement and returns from the function. Thus the 2nd return and the fclose will never be executed. You compiler should have caught this. Turn up the warning level to maximum. Commented Dec 11, 2013 at 0:56

2 Answers 2

1
for (row = 0; row<3; row++) //you have no open and close braces for this for loop
Sign up to request clarification or add additional context in comments.

1 Comment

It doesn't look like they are needed. I don't think that switch is meant to be part of the outer loop.
1

Suggestions:
1) Look up std::toupper or std::tolower so you don't have to use both upper and lower case letters in your case statements.

2) Create a index by subtracting letters:

unsigned int index = std::toupper(woodType) - 'A';
ftk = arraylocation[0][index];
fck = arraylocation[1][index];

3) A function can only return one value: ftk or fck. If you want to return more than one value, pass them by reference or put them in a structure and return a copy of the modified structure.

4) No execution flows after a return statement, so your code will never execute the 2nd return statement or the fclose.

1 Comment

Don't forget to bounds-check the index.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.