April 26th, 2003, 08:55 PM
help with simple if statements
im attempting to teach myself c++ due to the fact that the current highschool i attend has dropped any sort of computer teaching classes due to the NYC cutbacks :mad: so, you guys (and gals ;) ) will hear alot more from me. anyways, heres my first question!
i want this program to behave almost as a password system. if the proper name (patrick) isnt entered, then it tells you that you are not a legal user and shuts down. i've reached my first hurdle, i cant make the program say anything else except what is supposed to be said when the correct name is entered, even when the name is incorrect! what am i doing wrong? :(
std::cout<<"Enter your name\n";
std::cout<<"This is your name\n";
std::cout<<"you are not patrick! >:( \n";
std::cout<<"please close the program.\n";
also, i want the program to prompt you to close the program by typing "close" but it closes on its own!
all help will be apreciated! :)
April 26th, 2003, 09:40 PM
I'm confused. You say you want the user to enter his name, yet the variables are integers! Are you entering numbers or names?
Running it again as it is, try entering numbers and see what it does. Now, I'm not sure what cin does when it's told to expect a number and gets letters instead. The reason why it seems to blow through that cin<<close; could be that it thinks there are still characters in the input buffer.
Also, you shouldn't need to preface every cout and cin with std:: . Namespaces came out after my time, but I think there's a using statement you can put at the start of the program.
April 26th, 2003, 10:11 PM
i thought that i had to make the variables integers :confused: im not really sure what im doing, also im not sure what the buffer thing is (didnt get up to that chapter yet :p ) but, what am i supposed to do if the variables are all words (names) how do i define them? i didnt know how to do that so i defined them with numbers. im not sure about alot of things. how can i fix this so that i use only words, not numbers and that it will recognize the correct name?:confused: :confused: :confused:
April 27th, 2003, 01:31 AM
Something like this perhaps.
The using namespace std; statement saves you the trouble of typing std:: in front of cin, cout etc., because it qualifies the namespace for you. If you don't understand the rest, keep reading the book and it'll all make sense sooner or later. Hope this helps!
using namespace std;
cout<<"Enter your name\n";
cout<<"This is your name\n";
cout<<"you are not patrick! >:( \n";