So this is a program I wrote about a week ago and just today I decided to make it loop, but there's one problem with it that I don't understand - on the first go, everything is fine, but after it loops back to the beginning at least once, it skips the part where it asks me to type in the variable "sentence". I went through it with the debugger, and it goes through that line just fine, but doesn't ask me to type anything after it's looped back at least once. The same thing happened when I tried using a label at the beginning and used the "goto" command near the end.
Oh and there's one more thing, while I'm on the topic of this code, does anyone know how to put "" brackets as part of a string? Cause near the end where it says - "The sentence " << sentence - I want to put brackets around SENTENCE, but putting 1 double bracket on each side turns it into a string, and putting 2 double brackets on each side makes 2 empty strings.
cin.ignore(); // use this
cout << endl << "The sentence " << sentence << " has the letter " << sel_ch << " in it " << counter << " times." << endl << endl;
Ok, thx, that solves the entire 1st part of my question, but do you know about the other part? I'll just copy it here:
Oh and there's one more thing, while I'm on the topic of this code, does anyone know how to put "" brackets as part of a string? Cause near the end where it says - "The sentence " << sentence - I want to put brackets around SENTENCE, but putting 1 double bracket on each side turns it into a string, and putting 2 double brackets on each side makes 2 empty strings.
Ah, yes, thx, it finally works. I'll put the thread as solved and I've got a small off-topic question regarding classes and objects.
This is my 1st attempt at using classes and objects. The program itself doesn't do much, but the point was that I used classes and objects and I wanted to ask if this is an efficient use of classes & objects.
There's a couple of problems here. Its not the best way of using classes no. You want the actual class and all the function declarations inside the header file, but you want all the function definitions in the cpp file. You dont want them both in the same file like you have it right now.
Becuase it makes the code unreadable. imagine a big program with a a bunch of gotos instead of loops or whatever. And you're reading through it. Lets say you're at line of code 150. Then all of a sudden a wild goto appears. And it says. goto repeat;
And now you're like... where the fuck is this repeat? Is it in this file? Is it in a different file? is it above me, is it below me, etc etc, and imagine that with a bunch of gotos. Stick to loops buddy. :p
I might haven gotten it 100% right, you can google it for more information.