Go Back   EQEmulator Home > EQEmulator Forums > Archives > Archive::Development > Archive::Development

Archive::Development Archive area for Development's posts that were moved here after an inactivity period of 90 days.

Reply
 
Thread Tools Display Modes
  #1  
Old 06-24-2004, 07:59 PM
x-scythe
Discordant
 
Join Date: Jun 2003
Posts: 449
Default help with C++

been here like a year now and decided i want to learn C++ so i can help out more.
ive been practicing a few things since some of it seems to be the same as PERL. i ran into an error tho...
what i want this simple program to do is ask people to type in a username and then i want it to ask them for a password. people who put the wrong pass in get this message "Incorrect Pass. Good-Bye." and people who put the right one get this message "You have accessed my information. You are lame!" For some reason tho, every time you put in your username you get the message you would get for a correct password instead of the "Enter Password" prompt.
heres is the code
Code:
//basic pass

#include <iostream.h>
#include <stdio.h>

int main()
{
	//enter username
	int name;
	cout << "Enter Username:";
	cin >> name;

	//enter pass
	int pass;
	pass = 5;
	cout << "Enter Password:";
	cin >> pass;

	if(pass != 5)
	{
		cout << "Incorrect Password. Good-bye.";
	}
	if(pass == 5)
	{
		cout << "You have accessed my information! You are lame!";
	}

	return;
}
thats it...any help would be appreciated greatly.

also if anyone could respond with what exactly the beginning "int main()" function does would also be appreciated hehe...i have no clue what its for. i know it has something to do with declarations maybe?
Reply With Quote
  #2  
Old 06-24-2004, 08:42 PM
Virus11
Discordant
 
Join Date: May 2004
Posts: 311
Default

Weird, I spent like 20 miniutes and I still couldn't figure it out. Me and you are probally around the same c++ skill level :-(
__________________

Reply With Quote
  #3  
Old 06-24-2004, 08:43 PM
mangoo
Items Master
 
Join Date: Apr 2003
Posts: 293
Default

Code:
#include <iostream.h>
#include <stdio.h>

int main()
{
   //enter username
   char name[32];
   cout << "Enter Username:";
   cin >> name;

   //enter pass
   int pass = 0;
   cout << "Enter Password:";
   cin >> pass;

   if(pass != 5)
   {
      cout << endl << "Incorrect Password. Good-bye." << endl;
   }
   else if(pass == 5)
   {
      cout << endl << "You have accessed my information! You are lame!" << endl;
   }

   return 0;
}
Made a couple changes here.

1. Main problem you were seeing is because "name" was an integer and you were inserting text. So it immediately dropped to the if statements.

2. Changed "return;" to "return 0;"

3. Initialized "pass" to 0.



*EDIT* Added a little spacing to the code. *EDIT*

*EDIT* Made the second if statement an else if, not a big deal in this size program, but it's good habit to get in to. *EDIT*
__________________
Reply With Quote
  #4  
Old 06-25-2004, 01:13 AM
Scorpious2k's Avatar
Scorpious2k
Demi-God
 
Join Date: Mar 2003
Location: USA
Posts: 1,067
Default

Might want to change pass to a char too ....
__________________
Maybe I should try making one of these servers...
Reply With Quote
  #5  
Old 06-25-2004, 05:16 AM
x-scythe
Discordant
 
Join Date: Jun 2003
Posts: 449
Default

thanks for the help.
i dont understand tho what the [32] means after name....
thanks again
Reply With Quote
  #6  
Old 06-25-2004, 06:23 AM
mangoo
Items Master
 
Join Date: Apr 2003
Posts: 293
Default

Scorp: Yes, but he had everything setup for the password to == 5, so I just left that alone .

x-scythe: the [32] designates the size of "name". So in this case, "name" is 32 characters long.
__________________
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

   

All times are GMT -4. The time now is 01:25 AM.


 

Everquest is a registered trademark of Daybreak Game Company LLC.
EQEmulator is not associated or affiliated in any way with Daybreak Game Company LLC.
Except where otherwise noted, this site is licensed under a Creative Commons License.
       
Powered by vBulletin®, Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3