Thread: The noob(me) needs help again! plz...

  1. #1
    Registered User
    Join Date
    May 2007
    Posts
    21

    Exclamation The noob(me) needs help again! plz...

    Now I am making the login and signup app for my guessing number game. I did it all and with no bugs to report at all! I was excited; all that typing and no errors, but when I ran it... it ran fine. LOL There is one spot though. It checks to see if the username they entered is the same as the "loginid" from when they signed up. I have tried it many times using "1" as the username and it always sais that it is not correct. I will leave a note where this shouldn't be happening.
    Code:
    #include<iostream>
    #include<fstream>
    #include<cstring>
    #include<string>
    using namespace std;
    
    void main()
    {
    	char ready, alreadyup, correct;
    	string username, pass;
    	int work = 1;
    	void play();
    	string loginid, signpass;
    	cout<<"Welcome to Devon's amazing guess a number game!\n";
    	cout<<"Are YOU ready... Yes or No?\n";
    	cin>>ready;
    	if(ready == 'y')
    	{
    		do
    		{
    		cout<<"Have you already signed up? Yes or No?\n";
    		cin>>alreadyup;
    		if(alreadyup == 'y')
    		{
    			cout<<"Enter your username exactly as you put it: ";
    			cin>>username;
    			ifstream login("username");
    			if(loginid != username)   //This always happens
    			{
    				cout<<"Just as I thought! You aren't even signed up!\n";
    				work = 0;
    				login.close();
    			}
    			if(loginid == username)   //This isn't happening
    			{
    				cout<<"Wow, you weren't lying! Now enter your password...: \n";
    				cin>>pass;
    				if(pass != signpass)
    				{
    					cout<<"wrong password\n";
    					work = 0;
    				}
    				if(pass == signpass)
    				{
    					cout<<"Welcome "<<username<<". Now you are ready to play!";
    					
    				}
    			}
    		}
    		if(alreadyup == 'n')
    		{
    			cout<<"Well then, nows the time!\n";
    			do
    			{
    			cout<<"Please choose a username: ";
    			cin>>loginid;
    			cout<<"\nIs this correct? Yes or No? ";
    			cin>>correct;
    			}
    			while(correct == 'n');
    			cout<<"Your final choice is "<<loginid<<".\n";
    			cout<<"Now enter your password: ";
    			cin>>signpass;
    			cout<<"Your information has been saved...";
    			ofstream signup("username");
    			signup<<loginid;
    			signup<<"\n";
    			signup<<signpass;
    			system("PAUSE");
    			system("cls");
    			main();
    		}
    		}
    		while(work == 0);
    	}
    }
    Please help, and when it is done, I will post the full source for you to compile and run for your enjoyment! wooooohooooooo a noobs game! sweeeet!

  2. #2
    Registered User
    Join Date
    May 2006
    Posts
    903
    You never set loginid nor signpass.

  3. #3
    Registered User
    Join Date
    May 2007
    Posts
    21
    what do you mean? They were stored in a document that I saved them to after they signed up. Please exagerate, I am confused.

  4. #4
    Registered User
    Join Date
    May 2006
    Posts
    903
    Code:
    	char ready, alreadyup, correct;
    	string username, pass;
    	int work = 1;
    	void play();
    	string loginid, signpass;
    	cout<<"Welcome to Devon's amazing guess a number game!\n";
    	cout<<"Are YOU ready... Yes or No?\n";
    	cin>>ready;
    	if(ready == 'y')
    	{
    		do
    		{
    		cout<<"Have you already signed up? Yes or No?\n";
    		cin>>alreadyup;
    		if(alreadyup == 'y')
    		{
    			cout<<"Enter your username exactly as you put it: ";
    			cin>>username;
    			ifstream login("username");
    			if(loginid != username)   //This always happens
    			{
    				cout<<"Just as I thought! You aren't even signed up!\n";
    				work = 0;
    				login.close();
    			}
    			if(loginid == username)   //This isn't happening
    			{
    				cout<<"Wow, you weren't lying! Now enter your password...: \n";
    				cin>>pass;
    				if(pass != signpass)
    				{
    					cout<<"wrong password\n";
    					work = 0;
    				}
    				if(pass == signpass)
    				{
    					cout<<"Welcome "<<username<<". Now you are ready to play!";
    					
    				}
    			}
    		}
    Read again what I have told you.

    "You never set loginid nor signpass."

  5. #5
    Registered User
    Join Date
    May 2007
    Posts
    21
    I thank you for your effort but because I am a giant noob I don't get what your trying to say. The point is that if they have already signed up then loginid and signpass will already have been made, and if not then it hasn't been made. Again, I thank you for your efforts but I am a dumb noob.

  6. #6
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Please let's stop it already with the talk about being a noob. Either jump out of that mentality or just give it up and don't let it work.

    Code:
    ifstream login("username");
    This opens up a file named "username", but you never read from it. Therefore you can't possibly compare anything inside of it since you never read anything from it.

    Code:
    if(loginid != username)
    This is great except you never set loginid to anything as others are telling you. It's some random string that happens to be compared to username. That's not what you're supposed to do.

    So actually read from the file, and set loginid to something.

  7. #7
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    It's some random string that happens to be compared to username.
    Actually, it will be the string generated by the default string constructor, which is "". But that's still not what the OP wants.

    main() must return int, not void. http://faq.cprogramming.com/cgi-bin/...&id=1043284376

    Also, you should be aware that calling main() -- i.e., making main() recursive, directly or indirectly -- is invalid in C++. (In C it's okay, but not in C++.) Personally I think it's a stupid rule because you can just have main call another function, say, maintwo, and have maintwo recurse, but it's part of the standard.

    You should probably be printing a newline at the end of this string.
    Code:
    cout<<"Welcome "<<username<<". Now you are ready to play!\n";
    As for this:
    Code:
    			ofstream signup("username");
    			signup<<loginid;
    			signup<<"\n";
    			signup<<signpass;
    			system("PAUSE");
    			system("cls");
    You should probably be calling signup.close(), especially since you might open the file again at a later point in time from the same program. (Opened files are usually closed automatically when a program exits, but if you try to open a previously-opened file without closing the previous file, it usually doesn't work.)

    And system() is probably a bad idea. I'd suggest using cin.get() instead of system("pause") and eliminating system("cls") if possible. Or print lots of newlines. Or leave them in.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  8. #8
    Registered User
    Join Date
    May 2007
    Posts
    21
    I don't get the reading part. I have been looking all over the internet trying everything that comes up, and nothing works. If someone could please post what I should do with an example, I would be very grateful. In the meantime I will keep trying.
    NOTE: I fixed some things you noted dwks. And thanks to everyone who has, is, or ever will aid me in my everlasting quest for C++ knowledge. =O

  9. #9
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    With cin, you need to go cin>>variable before variable holds anything of value. It's the same thing with files.
    Code:
    login >> variable;
    Also see this tutorial: http://www.cprogramming.com/tutorial/lesson10.html
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  10. #10
    Registered User
    Join Date
    May 2007
    Posts
    21
    I deeply appologize for all you have done, but nothing anyone has said has effected my brain... I know you have tried really hard but I need deep, idiot-proof explanation of my error and another one for my solution. I have read through the tut and with where I am at now, it seemed not to make a difference. Again I appologize for your hard work being brought in through one ear and quickly departing through the other.

  11. #11
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Stop posting for a second and read the replies multiple times.

    It doesn't matter that you have a file. The data inside of it is meaningless unless you open the file and read from it. You've been told this repeatedly that you never read from the file. You attempt to open it and then ignore it.

    If you can't understand this, take a break and put this project on hold. Write something much simpler that deals with files. Get to understand files very well.

  12. #12
    Registered User
    Join Date
    May 2007
    Posts
    21
    I'll try that. Thank you very much, and sorry for the inconveniance. Talk to ya later

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can any1 plz make this assignment
    By jean in forum C Programming
    Replies: 17
    Last Post: 05-13-2009, 09:19 PM
  2. [Request] Need Help Plz
    By TylerD in forum Tech Board
    Replies: 4
    Last Post: 01-03-2009, 09:54 AM
  3. plz help here, noob actually .D
    By BjoRn3n in forum C++ Programming
    Replies: 1
    Last Post: 03-07-2005, 03:04 PM
  4. Anyone plz help me
    By Rose_Flowers in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 09-17-2003, 12:01 PM
  5. help plz plz
    By nsssn73 in forum C++ Programming
    Replies: 2
    Last Post: 06-03-2002, 08:44 AM