C++: IntelliSense expected while & C1075 "end of file found before the left brace at {?

Im trying to create a program with a menu and there are 3 choices 0, 1 and 2. Im pretty sure that options 1 and 2 are correct in their DO, IF and ELSE IF statements but, the error shows up in the 0 option and the program wont run. I wanted to know if anyone sees anything wrong with this part of the program?

heres part of the program that I believe has the error:

else if (menu == 0)

{

cout << "Exit Program Y/N? : ";

cin >> ans;

}

while (ans != "y" && ans != "Y")

_getch();

return 0;

}

~ <<< there is a squiggly line here under this bracket and the 2 errors that I get is

''IntelliSense :expected 'while'' and ''error C1075 end of file found before the left brace '{' how do I fix this? Someone please help.

2 Answers

Relevance
  • Anonymous
    7 years ago
    Favorite Answer

    should be like

    do

    {

    ..

    ...

    ...

    }while (answer != 'y' && ...);//you need ; there. If ans is a string I guess you use "y" or "Y" and not char

    getch()

    return 0;

    }

  • 7 years ago

    You just forgot a brace. More specifically, a left brace like the compiler told you.

    Actually scratch that. Looks like you added an extra brace at the end right, so delete it.

    Actually scratch that too (guessing the final brace closes your main() function). Need the full code, though you've added or forgotten a brace somewhere along the line so maybe you can find on your own. Also you'll want to change

    while (ans != "y" && ans != "Y")

    to

    while (ans != 'y' && ans != 'Y')

    "y" is a 2 character string (y followed by the null character) while 'y' is a character.

Still have questions? Get your answers by asking now.