Thread: help with C++
View Single Post
  #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