no, thats why i posted it here in the first place.
when i try to compile this code, which is how i want it to be, it says that there is an error on the line
any ideas?Code:else if (answer ==1)
no, thats why i posted it here in the first place.
when i try to compile this code, which is how i want it to be, it says that there is an error on the line
any ideas?Code:else if (answer ==1)
It's been said several times. You must pair an else if with an if. You cannot have a floating else if just sitting in the middle of the code.
yes i no this has been said already- also as i have said, and annotated in code, it is paired with an if statement.
unless i have to do something special to pair it with an if statement i cant see wat you mean
here is wat i mean
Code:if (answer != 1)//this is the if that the else if shoud be paired with { std::cout << "\nWell if you're not going to believe me. . .\n"; std::cout << ". . .maybe I should add some more. Would you like that?\n"; std::cout << "\n\n1 = yes\n"; std::cout << "2 = no\n\n"; std::cout << ">> "; std::cin >> answer; //you forgot to get the answer for the 2nd question std::cin.get(); //catch the enter input } else if (answer == 1)//this is the else if { for (int y = 0; y < 100000; y++) { std::cout << y << std::endl; } std::cout << "\nGood....Thats very good. For i have now removed them all!\n"; std::cout << "Press enter to quit\n"; std::cin.get(); } std::cout << "\n\nAnd again please....\n\n"; std::cin.get(); return 0;
That code is different than the code you posted earlier. In that code, the else if is correctly paired with the if above it, because the statement after the if is a block of code (the code between and including the braces) followed immediately by the else. In the earlier code that was wrong, there were several statements after the if and before the else if that were not enclosed in braces to form a single block, which is why the else if had nothing to pair with and got the error.
If you still get an error with the above code exactly as is, you should start a new thread with this new error, the exact error message including line number, and the full code.
ah i see. the complete problem was me not putting the braces in the right place.
thanks to everyone that has tried to tell me what i was doing wrong