Jamin2112
- 973
- 12
It's saying I don't have an 'if' statement for my 'else if' statement, but I do. You can see clearly from this picture that I do.
DavidSnider said:Please post the relevant code instead of a screenshot.
Also, when your code looks like this it is time to simplify it by factoring out common functionality.
if (answers[i].charAt(k - 1) == 'a' || answers[i].charAt(k - 1) == 'A') {
introvertQuestionsAns++;
} else if (answers[i].charAt(k - 1) == 'b' || answers[i].charAt(k - 1) == 'B') {
introvertNum++;
introvertQuestionsAns++;
}
} else if (answers[i].charAt(k - 1) == 'a' || answers[i].charAt(k - 1) == 'A') {
intuitionQuestionsAns++;
} else if (answers[i].charAt(k - 1) == 'b' || answers[i].charAt(k - 1) == 'B') {
intuitionNum++;
intuitionQuestionsAns++;
}
} else if ((k + 7) % 7 == 4 || (k + 7) % 7 == 5) {
if (answers[i].charAt(k - 1) == 'a' || answers[i].charAt(k - 1) == 'A') {
feelingQuestionsAns++;
} else if (answers[i].charAt(k - 1) == 'b' || answers[i].charAt(k - 1) == 'B') {
feelingNum++;
feelingQuestionsAns++;
}
} else {
if (answers[i].charAt(k - 1) == 'a' || answers[i].charAt(k - 1) == 'A') {
perceivingQuestionsAns++;
} else if (answers[i].charAt(k - 1) == 'b' || answers[i].charAt(k - 1) == 'B') {
perceivingNum++;
perceivingQuestionsAns++;
}
}
if ((k + 7) % 7 == 1) {
if (answers[i].charAt(k - 1) == 'a' || answers[i].charAt(k - 1) == 'A') {
introvertQuestionsAns++;
} else if (answers[i].charAt(k - 1) == 'b' || answers[i].charAt(k - 1) == 'B') {
introvertNum++;
introvertQuestionsAns++;
}
} else if (answers[i].charAt(k - 1) == 'a' || answers[i].charAt(k - 1) == 'A') {
intuitionQuestionsAns++;
} else if (answers[i].charAt(k - 1) == 'b' || answers[i].charAt(k - 1) == 'B') {
intuitionNum++;
intuitionQuestionsAns++;
}
} else if ((k + 7) % 7 == 4 || (k + 7) % 7 == 5) {
if (answers[i].charAt(k - 1) == 'a' || answers[i].charAt(k - 1) == 'A') {
feelingQuestionsAns++;
} else if (answers[i].charAt(k - 1) == 'b' || answers[i].charAt(k - 1) == 'B') {
feelingNum++;
feelingQuestionsAns++;
}
} else {
if (answers[i].charAt(k - 1) == 'a' || answers[i].charAt(k - 1) == 'A') {
perceivingQuestionsAns++;
} else if (answers[i].charAt(k - 1) == 'b' || answers[i].charAt(k - 1) == 'B') {
perceivingNum++;
perceivingQuestionsAns++;
}
}
}
} // what is this closing?
else if ((k + 7) % 7 == 4 || (k + 7) % 7 == 5)
DavidSnider said:Code:} } // what is this closing? else if ((k + 7) % 7 == 4 || (k + 7) % 7 == 5)
int offset = (k + 7) % 7;
char answer = Character.toUpperCase(answers[i].charAt(k - 1));
if (offset == 1)
{
if (answer == 'A')
{
introvertQuestionsAns++;
}
else if (answer == 'B')
{
introvertNum++;
introvertQuestionsAns++;
}
}
else if (answer == 'A')
{
intuitionQuestionsAns++;
}
else if (answer == 'B')
{
intuitionNum++;
intuitionQuestionsAns++;
}
else if (offset == 4 || offset == 5)
{
if (answer == 'A')
{
feelingQuestionsAns++;
}
else if (answer == 'B')
{
feelingNum++;
feelingQuestionsAns++;
}
}
else
{
if (answer == 'A')
{
perceivingQuestionsAns++;
}
else if (answer == 'B')
{
perceivingNum++;
perceivingQuestionsAns++;
}
}
DavidSnider said:I have a feeling the entire structure of this code isn't doing what you want it to. I would rethink it.
Lets just say you decided to refactor it like this:
Code:int offset = (k + 7) % 7; char answer = Character.toUpperCase(answers[i].charAt(k - 1)); if (offset == 1) { if (answer == 'A') { introvertQuestionsAns++; } else if (answer == 'B') { introvertNum++; introvertQuestionsAns++; } } else if (answer == 'A') { intuitionQuestionsAns++; } else if (answer == 'B') { intuitionNum++; intuitionQuestionsAns++; } else if (offset == 4 || offset == 5) { if (answer == 'A') { feelingQuestionsAns++; } else if (answer == 'B') { feelingNum++; feelingQuestionsAns++; } } else { if (answer == 'A') { perceivingQuestionsAns++; } else if (answer == 'B') { perceivingNum++; perceivingQuestionsAns++; } }
The flow control doesn't seem to make much sense, does it?
(k + 7) % 7
k % 7