Hey I'm a beginner in the art of C++ and I really cant see the problem here. My goal is to make a little noob-program that asks to put in so many dirty words you can think of that you would like to censor. Following I want it to ask for a welcome sentence for the user to write. And if it detects any of the dirty words you wrote earlier to BE in that welcome-sentence, the program should replace that dirty word with a "BLEEP". Last it should write out your sentence censored like this: "Ok ''your sentence'' Thank you!" And then keep the window open to examine whats has happened.
int main()
{
cout<<"(Just for the hell of it)\n- Write down every dirty word you can \nthat you want to censorize from future text!\n(end and confirm your words by hitting RETURN and 'Ctrl+Z' and RETURN again)\n";
FailwordsVector();
cout<<"How do you give your greetings in swedish? I wanne be able to greet the swedish king at the banquet properly.\n(end and confirm the sentence by clicking 'Ctrl+Z')\n";
SentenceVector();
cout<<"Ok, ''";
for(unsigned int i=0; i<sentence.size(); i++){
for(unsigned int q=0; q<failwords.size(); q++){
if(sentence[i] == failwords[q]){
sentence[i] = "*BLEEP*";}
}
cout<<sentence[i]<<' ';
}
cout<<"'' Thank you!";
keep_window_open();
}
________________________________________
I got about 10 error messages running this all saying that the vector sentence and failswords could not be found. Before I also tried to do it like this:
#include "std_lib_facilities.h"
int main()
{
cout<<"(Just for the hell of it)\n- Write down every dirty word you can \nthat you want to censorize from future text!\n(end and confirm your words by hitting RETURN and 'Ctrl+Z' and RETURN again)\n";
cout<<"How do you give your greetings in swedish? I wanne be able to greet the swedish king at the banquet properly.\n(end and confirm the sentence by clicking 'Ctrl+Z')\n";
____________________________________
And this worked fine except that it never executed anything after "cout<<"How..../" except the "cout"statements below, skipping my other vector and for-loop.
Any answer to why it doesnt acknowledge my variabels in the first bunch of code and why it never execute the rest in the second bunch of code would be VERY helpfull. +If you know some other improvements or other solutions to this problem :=)
Kind regards//The Failing Student
PS. I'm swedish so have that in mind when answering. Thanks DS.
Variables are only visible in their scope and they are destroyed at the end of the scope.
If you need failwords and sentence outside the functions, you need to return them.
In reply to Athar:
aaaaah so THATS whats the "return" is for.... ok, thanks.
In reply to Return 0 (lol):
std_lib_facilities.h is a library that I found thanks to my friend "Bjarne Stroustrup" on his site. It contains everything you basically would need to include.... + using namespace std a.s.o. My guess would be that you can ignore it. Keepwindowopen is also declared in that header. That function does what it supposed to do.
Any idea on why the SECOND solution doesnt work? I can just ignore the functionsolution, but I wonder why my other solution with everything in main doesnt execute everything.
Any thoughts on that?