Oh... Thanx.
Oh... Thanx.
Read my previous post's edit.
Trinity: "Neo... nobody has ever done this before."
Neo: "That's why it's going to work."
c9915ec6c1f3b876ddf38514adbb94f0
Ok, it works pretty well, but there's one thing thats bugging me. After every definition, it says the cout in my else statement.
Make sure you have all your definitions in else if statementsOriginally Posted by pandapwnage
if()
else if()
else if()
else if()
else
jmd15, I wasnt refering to your coding abilities by saying "what kind of C++ Programmer are you". I said that because you posted C when your title says C++ What I said after that wasn't meant to continue from that as criticism, just pointing out so the OP knows, yah know.
Just a note that the way this program is setup it wont be able to handle more than this simple program, and just so you know for later projects.. using a while statement would also work here, instead of goto, like so:
Thats usually how its done.Code:int main() { char name[256]; while(1) { cout<<"Enter a name: "; cin>> name; cin.ignore(); if( strcmp(name,"exit")==0) break; if ( strcmp(name,"Shayne")==0 ) cout<<"Shayne is a twenty fifth dinosaur pagent.\n"; else if ( strcmp(name,"Jamie")==0 ) cout<<".... and so on and so on for like 10 names..\n"; else cout<<"....\n"; cin.get(); } }
Last edited by Dae; 09-30-2005 at 09:51 PM.
Warning: Have doubt in anything I post.
GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101
Yes, that is also a good way to do it. Probably even a better way. Just a note, in your if statements(this includes else if, and else) you use brackets around the code to be executed if that condition is true. UNLESS you only have one line of code to be executed then you don't need brackets, but maybe is a good idea just to get into the habit so you don't forget them.
@ Dae:
Sorry for getting angry, I interpreted your comment in the wrong way.
Last edited by jmd15; 10-01-2005 at 07:54 AM.
Trinity: "Neo... nobody has ever done this before."
Neo: "That's why it's going to work."
c9915ec6c1f3b876ddf38514adbb94f0
strcmp is in <cstring>, not <string>.
You should use Dae's first version that uses the C++ string class (with one change: add #include <string>). It is easier and safer to use than the C-style character arrays in jmd15's examples.