cout<<"Please do not use spaces in your answer, it will mess up the program due to bad writing =/ "<<endl;
cout<<endl;
/* Yes I'm rubbish ok? */
cout<<"Please enter either he/she, according to your gender: ";
cin>> gender;
cin.ignore();
cout<<"And what is your first name?: ";
cin>> fname;
cout<<"Well hello there, "<< fname <<"! What is your surname?: ";
cin>> sname;
cin.ignore();
cout<<"Thanks. So far you have told me that you are a "<< gender <<", and your name is "<< fname <<" "<< sname <<"."<<endl;
cout<<endl;
cout<<"What is the one thing you hate most?: ";
cin>> hate;
cin.ignore();
cout<<"What is your weapon of choice?: ";
cin>> wep;
cin.ignore();
cout<<"What is your favourite hobby/pastime?: ";
cin>> hobby;
cin.ignore();
cout<<endl;
cout<<"Ok, let's begin our story..."<<endl;
cout<<endl;
cout<<endl;
cout<<""<< fname <<" "<< sname <<" thought "<< gender <<"'d take a break from "<< hobby <<"."<<endl;
cout<<""<< gender <<" decided to rid the world of all traces of "<< hate <<", once and for all."<<endl;
cout<<"So, brandishing a "<< wep <<", "<< gender <<" set off to seek out and destroy "<< hate <<"..."<<endl;
cout<<"But "<< gender <<" died on the mission and "<< hate <<" remained forever more."<<endl;
cout<<"Poor "<< fname <<", "<< gender <<" should have stuck with "<< hobby <<"."<<endl;
cin.get();
return 0;
}
As you can see, I'm a total n00b with only a basic knowledge of int, float and char. I was wondering which type i could use so that you choose one of 2 options, and most importantly, how I could allow spaces to be used in input without messing up how the program remembers it. Tried google but failed.
Ah I see from the error log I need to look up init-declarors, any help? I'll google it anyway.
"expected init-declarator before "enum"
expected `,' or `;' before "enum""
Name:
Anonymous2007-06-12 12:20 ID:NALSuzi+
*declarator, even
Name:
Anonymous2007-06-12 12:22 ID:rO+ytXoJ
What exactly are you trying to do/ you can't have strings in an enum. don't let these people discourage you, c++ is easy really.
Name:
Anonymous2007-06-12 12:25 ID:NALSuzi+
>>16
Thanks.
I was trying to make a multiple choice thing, such as hit M/F (male/female), or only allow male/female or he/she to be entered.
I'm also gonna have to work out strings, so when someone inputs with space characters the program remembers things correctly.
Name:
Anonymous2007-06-12 12:59 ID:NALSuzi+
Ok, I'm finding a lot of info on init-declarators, but can't work out which things I actually use.
Anyone know a site which might explain this better?
Name:
Anonymous2007-06-12 13:02 ID:NALSuzi+
>>18
meh, i'll just forget about that for now actually, considering what >>16 said. I'll learn up on strings instead.
Name:
Anonymous2007-06-12 13:04 ID:EQ/rLPL/
Blargh. Just read SICP (or watch the videos if you're lazy). Then go back to C++ if you still think it is a good idea (you won't).
Name:
Anonymous2007-06-12 13:14 ID:NALSuzi+
>>20
I want to learn C++.
I want to want to learn C++.
[code]#include <iostream>
using namespace std;
int main()
{
char m[]="male";
char f[]="female";
char o[]="dunno lol";
char* gender=o;
std::string g;
cout<<"What is your gender?";
cin>> g;
if(strcasestr(g.c_str(),"male")&&!strcasestr(g.c_str(),"female"))gender=m;
if(strcasestr(g.c_str(),"female")&&!strcasestr(g.c_str(),"male"))gender=f;
cin.ignore();
cout<<"You are "<< gender <<"."<<endl;
cin.get();
return 0;
}[code]
Name:
Anonymous2007-06-12 13:21 ID:EQ/rLPL/
>>21
Okay. After ten years, at least remember Anonymous told you it was a very bad idea and see that he was right.
Name:
Anonymous2007-06-12 13:22 ID:NALSuzi+
>>22
That doesn't seem to work, but thanks for pointing me in the right driection.
I'll go and register on some c++ forum or other, no offence guys but all this saging, and general trying to put me off is starting to get to me.
>>24 http://4-ch.net/wiki/#UsingSage Sage is not a insult.
Contrary to popular belief, sage should never be considered as a rude gesture or insult. In fact, someone writing insults or trolls to the thread and posting with sage are doing a good thing, since their useless post won't be brought to the attention of the rest of the board. The idea of sage being an insult came from imageboards, where filling up a thread with enough posts would get it removed. However, threads on channel4 take one thousand posts before they are closed, so the effect doesn't work here.
>>24 I'll go and register on some c++ forum or other
I think that is a good idea in your case. You're greatly hurting your programming, and if you really want to do that, doing it with other people living the same mistake will probably be a lot less painful.
no offence guys but all this saging, and general trying to put me off is starting to get to me.
Saging is not an insult. People telling you to ditch C++ are seriously trying to help you. I made the mistake of blindly using C++ against all odds for over five years, and would not want anyone to repeat it, but I think no one will speak sense into your mind.
>>28
Almost everything. The whole premise -- ``let's completely misunderstand OO and bolt on a horrible caricature of an OO system onto the macro assembler known as C for no obvious reason, and spice up the mix by bringing in non-features that serve no other purpose but to make the language more complex'' is ridiculous, to begin with.
All SICP trolling aside, I seriously suggest you forget everything you think you know about programming and at least watch through all the SICP video lectures once before continuing to hurt your learning with C++.
int main() {
string name;
cout << "What is your name?\n";
getline(cin, name);
cout << "y helo thar " << name << "\n";
}
Name:
Anonymous2007-06-12 16:28 ID:xZgyyQaD
Seems to be more opposition to C++ as time goes by. Maybe it's getting old?
Personally I have mixed feelings about C++.
Sometimes I like how rigid it is, you really have to plan the structure of a program, the structures and the relationships and when you have your program finished it will be faster than most other langauges.
On the downside development using C++ is S L O W compared to other languages (I mean in the order of 10-100 times longer development times compared to using say Python).
So what's more important development time, or running time and ego? ;)
(I'm >>16, I believe C++ has its uses but they are limited. Even game programmers are starting to use other languages (such as C#, could it be a dying language in a few years, or will the updates save it? (even though they have some nice changes I doubt it).
>>33
That's insane. Haskell gives you all the rigidness without the asshattery and failure of C++, together with an extremely high level language and very nice performance. The only actual need for C++ exists in 1337 gaem progm4mm4erz' small minds.
int main() {
string name;
cout << "What is your name?\n";
getline(cin, name);
cout << "y helo thar " << name << "\n";
cin.get();
}
worked great thanks!
>>39
My Python code almost always works. It's not a matter of having a system that gets anal over things. It's a matter of proper design. Anal languages somewhat force you to design properly. QUACK MOTHERFUCKER languages don't require you to waste more time than strictly necessary (your classes still have type, but you don't restrict how things work as long as they work (exist in a dictionary)), and you don't get annoyed because it doesn't compile. Yes, you can fail it. Yet if you have the same skill you need for anal typing, you produce the same sensible code and get the same reliable results, without the hassle and without needless definitions.
Name:
Anonymous2007-06-12 18:59 ID:2ChRYdt0
>>36
But Haskell is faster to develop in, when you finally DO get it
Name:
Anonymous2007-06-12 19:19 ID:NALSuzi+
Ok here's my re-write; thanks for the help guyz.
#include <iostream>
#include <string>
using namespace std;
int main()
{
string gender, fname, sname, hate, wep, hobby;
cout<<"Hello!"<<endl;
cout<<endl;
cout<<"Please enter either he/she, according to your gender: ";
getline(cin, gender);
cout<<endl;
cout<<"What is your first name?: ";
getline(cin, fname);
cout<<"Thanks, "<< fname <<"!";
cout<<"What is your surname?: ";
getline(cin, sname);
cout<<endl;
cout<<"Ok. So far you have told me that your name is "<< fname <<" "<< sname <<", and that you are a "<< gender <<".";
cout<<endl;
cout<<endl;
cout<<"What is the one thing you hate most?: ";
getline(cin, hate);
cout<<"What is your weapon of choice?: ";
getline(cin, wep);
cout<<"What is your favourite hobby?: ";
getline(cin, hobby);
cout<<"Time to write the story!"<<endl;
cin.get();
cout<<endl;
cout<<endl;
cout<<""<< fname <<" "<< sname <<" thought "<< gender <<"'d take a break from "<< hobby <<"."<<endl;
cout<<""<< gender <<" decided to rid the world of all traces of "<< hate <<", once & for all."<<endl;
cout<<"So, brandishing a "<< wep <<", "<< gender <<" set off to seek out & destory "<< hate <<"..."<<endl;
cout<<"But "<< gender <<" died on the mission, and "<< hate <<" remained forever more"<<endl;
cout<<"Poor "<< fname <<", "<< gender <<" should have stuck with "<< hobby <<"."<<endl;
cout<<endl;
cout<<"The End"<<endl;
cin.get();
return 0;
}
If there's a way I can improve this I'd be glad to hear it.
in b4 more flaming...
Name:
Anonymous2007-06-12 22:58 ID:PmfpJL6j
I find it easy to spot the stack errors in smalltalk.
>without the hassle and without needless definitions.
needless definitions?
do you know TYPE INFERENCE?