int main() { List L; string x; cout << "Bufer is Empty! nn"; cout << "For the Add Elements Press 'A':n"; { char v = getch(); if (v == 'a') { cout << endl; cout << "Enter Elements: n"; start: getline(cin, x); L.ElAdd(x); cout << "--------n"; } cout << "Elements of Your List:\n\n"; L.print(); cout << "--------nn"; cout << "For the Continue of Adding Press 'P':n"; cout << "For the Clear Buffer Press 'C':n"; v = getch(); if (v == 'p') { cout << "Enter the Next Element: n"; goto start; } } system("PAUSE"); return EXIT_SUCCESS; } 

I can’t get rid of goto! I do with while, and there all goes in cycles! Help me deal with this problem. I was told to forget about the goto in the future, so I have been trying for an hour. But nothing comes out. As I said, it goes in cycles and displays not what I want and got with goto.

    1 answer 1

    Here, the do-> while construction is just right:

    UPD: It was necessary to count the number of open and closed brackets "{" and "}" and everything would be clear at once:

      int main() { List L; string x; cout << "Bufer is Empty! nn"; cout << "For the Add Elements Press 'A':n"; char v = getch(); if (v == 'a') { cout << endl; cout << "Enter Elements: n"; do{ getline(cin, x); L.ElAdd(x); cout << "--------n"; cout << "Elements of Your List:\n\n"; L.print(); cout << "--------nn"; cout << "For the Continue of Adding Press 'P':n"; cout << "For the Clear Buffer Press 'C':n"; v = getch(); if (v == 'p') cout << "Enter the Next Element: n"; }while(true); } system("PAUSE"); return EXIT_SUCCESS; } 
    • I did the same! But it did not work correctly! ( - navi1893
    • What exactly did not work out? - AseN
    • Well, here and on your code as swears, as well as on mine! Here are the errors: 1. expected while' before "cout" 2. expected (' before "cout" 3. expected `) 'before'; ' token - navi1893
    • Changed the answer above. - AseN
    • Yes thank you! I accepted your answer. - navi1893