I apologize immediately for such a cumbersome code, it’s me so that you understand more clearly. I want every time I enter an element, the counter counts the number of characters in the element and when outputting elements it also displays the number of characters (TOTAL) in the elements below it. Not in one, but in all elements (5, 10, 15, etc.). It is not for you to decide for me, I just coped with one of the elements, but with a few not, please help with this.
#include <iostream> #include <conio.h> #include <string.h> using namespace std; struct element { string data; element *adress; }; class List { private: element * StartAdress, *FinishAdress; public: List() { StartAdress = NULL; FinishAdress = NULL; } void ElAdd(string a) { element *e; e = new element; e->data = a; /*e -> adress = StartAdress; StartAdress = e; */ if (StartAdress == NULL) { StartAdress = e; } else { FinishAdress->adress = e; } FinishAdress = e; FinishAdress->adress = NULL; } void print() { element *e; for (e = StartAdress; e != NULL; e = e->adress) cout << e->data << " " << endl; } }; 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:nn"; 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; }
what you advised me displays errors, which I described in the 7th comment of the 1st answer. Please help me with errors.
if
, and it’s generally a horror. - ReinRausgoto
, if it doesn't work out, ask a new question, and in the future forget the wordgoto
forever. This is just a little advice. - ReinRaus