He does state somewhere that scoping the using declarations is better than putting outside of everywhere.
Yeah, he does, which I why I originally conceded to computerquip. Then he deleted his post and reposted something that applies to more than just proper namespace usage, so I changed my post to reflect that.
My original post was made because I'd misread that particular paragraph in TC++PL, so my original point was wrong.
#include <iostream>
usingnamespace std;
int main()
{
int a;
cout << "1 for coke.2 for sprite,3 for fanta, 4 for water. 0 to quit"<<endl;
cin>>a;
while (a !=0)
{
if (a > 4)
{
cout <<"That was not a valid option.";
cout<<"Would you like to choose again?"<<endl;
cin>>a;
}
if (a == 1)
{
cout<<"You chose coke"<<endl;
cout<<"Would you like to choose again?"<<endl;
cin>>a;
}
if (a == 2)
{
cout <<"You chose sprite.";
cout<<"Would you like to choose again?"<<endl;
cin>>a;
}
if (a ==3)
{
cout<<"You chose Fanta.";
cout<<"Would you like to choose again?"<<endl;
cin>>a;
}
if (a==4)
{
cout<<"You chose water.";
cout<<"Would you like to choose again?"<<endl;
cin>>a;
}
}
cout<<"Thanks for coming??";
cin.get();
return 0;
}
And yes, I used namespace std;I tried to use the other one, but I kept getting an error. Would someone care to tell me what's wrong with globally declaring the namespace?
Just wait until you want to declare a global symbol called 'max', or 'sort', or 'complex'. Then, you'll maybe learn, but most likely you'll just rename it and go on using the using keyword. That is, until you have around four different namespaces in global scope and will be damned to patiently resolve the hundreds of compiler errors you'll inevitably get.
I also started using stdio.h in C++ a while ago because I was told it was faster.
Also you spelt FAQ as FQA on number 10.
Edit: also you tried to use an HTML tag on number 8.
Latest Graduation program. Run completely however, it runs for about 10 seconds on my computer since it fails to kill them off when they get to high in numbers and outputs well over a megabyte of text.
If you're looking at the code, ignore the OutputManager for now. I'm still implementing it (correctly) and I'll finish it today since its the actual reason I started working on the program.
Don't need to close ever really, streams will close when they are destructed.
//Don't complicate, just pass the whole mother.
What if I just want to make a certain color bunny?
Why do you need va_args? Just pass a vector (or just add the streams later with an addStream function into a vector, so that the user can add streams whenever)
There were probably some other weird things in there I missed...
1) @ rand() equation: I don't know. If I change it to some other shorter form, it doesn't work and isn't random at all. I found it rather strange and I couldn't figure out why but I'm leaving it as is for now until I figure out a more accurate equation or until I probably get rid of rand() entirely for randomness fun :D. I just wanted something that worked here lol.
2) You can't make a bunny a certain color. Its in the challenge description. It's either random at the beginning and they always inherit the mothers color.
3) In the Game constructor: Game(std::ostream& _out = std::cout), you have to choose the streams you wish to output to. The comment was made just to remind me to make some solution to pass multiple streams.
I like the comment on line 40.
However, I'm not sure what to think about the comments on lines 36 and 37.
The comment on line 43 frightens me.
I don't like the C++ FQA site. Its purpose is to indoctrinate hatred of C++, and uses outlandish arguments. You can't kill an abstract object with hate. Further, the author of the site is so fond of logical fallacies I stopped perusing it. One thing is always true: personal bias trumps all reason and discourse.
@Duoas, static std::vector<std::string> firstNames; //List of bunny names. Static to prevent huge memory usage ( one instance ).
This? Yes, static doesn't do that in classes. In a class, static makes the variable accessible from outside the class without using an object (that's why std::string::npos works)
the comments on lines 36 and 37.
1 2
int color; //Male / Female
int gender; //White / Brown / Black / Spotted
Lol!
I don't like the C++ FQA site. Its purpose is to indoctrinate hatred of C++, and uses outlandish arguments.
It has some good arguments, but otherwise, I agree with you.
bRadioactiveMutantVampireBunny? WTF!?!
EDIT: That was a joke. See later post for details.
The FQA website does fail to list exactly one language we should use instead of C++.
EDIT: Python? It's so much slower, although it is less forgiving for smaller jobs.