Help With Program

This is a discussion on Help With Program within the C++ Programming forums, part of the General Programming Boards category; Hi im beginning in C++ just started liek 2 days ago and I need some help. The code that posts ...

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    9

    Help With Program

    Hi im beginning in C++
    just started liek 2 days ago and I need some help.
    The code that posts below runs fine, as far as OPTION 1 is concerened (youll understand when u read far enough or compile the code yourself).

    Option 1 is "change your password".
    It asks you to enter your current password.
    to continue u must enter in ur current password. Now, I am trying to build it so that if you enter the wrong current password, it will not let you pass and wiill ask you to enter your password again.
    what happens is is that it still continues with the option that will ask you to enter a new password. I dont know why. Can someone help me with the code.

    Plus, this is all jsut practice. with conditional statements for the most part.

    Here is the code.
    Code:
    #include <iostream>
    using namespace std;
    main(){
         int a = 256781; //password
         int h = 24781; //pin number
         int current; //current password
         int newcurrent;//new current password
         int newcurrenta;//confirmation password
         int k;//second input of password (option 1)
         cout<<"Please enter your 6-digit password\n";
         cin>>a;
         cin.ignore();
         for ( a == 256781; a != 256781; ){
               cout<<"Incorrect Password. Please try again.\n";
              cin>>a;
                       }
         if (a=256781){
                      cout<<"You have correctly entered your password\n";
                      cout<<"Please type in your 4-digit pin to continue:\n";
                      cin>>h;
                      cin.ignore();
                      cout<<"\n";
                      cout<<"\n";
                                   for ( h == 24781; h != 24781; ){
                                         cout<<"You have entered an incorrect pin. Please try again\n";
                                         cin>>h;
                                             }
                                   if (h == 24781){
                                        
                                    
                                   
                                               cout<<"Welcome to your writers account\n";
                                               cout<<"What would you like to do?\n";
                                               cout<<"\n";
                                               cout<<"1 Change your password\n";
                                               cout<<"2 Create a new file\n";
                                               cout<<"3 Modify an existing file\n";
                                                   int option; //option list
                                                   cin>>option;
                                                   cin.ignore();
                                                  switch ( option ) {
                                                        case 1:
                                                               cout<<"Enter your current password\n";
                                                               cin>>k; 
                                                               cin.ignore();
                                                               for ( k = 256781; k != 256781;){
                                                                   cout<<"The password you entered is incorrect\n";
                                                                   cout<<"Please try again\n";
                                                                   cin>>a;
                                                                   cin.ignore();
                                                                   }
                                                               if (k == 256781){
                                                                   cout<<"Please enter a new password\n";
                                                                   cin>>newcurrent;
                                                                   cin.ignore();
                                                                   cout<<"Please enter your password again\n";
                                                                   cin>>newcurrenta;
                                                                   cin.ignore();
                                                                                for ( newcurrent ==newcurrenta; newcurrent != newcurrenta; ){
                                                                                      cout<<"The password you entered was incorrect.\n";
                                                                                      cout<<"Please try again\n";
                                                                                      cin>>newcurrenta;
                                                                                      }
                                                                                if (newcurrent==newcurrenta){
                                                                                      cout<<"Congratulations. Your password has been changed\n";
                                                                                      cout<<"would you like to do anything else?";
                                                                                                              }             
                                                               
                                                               
      
                                                                   break;
                                                         case 2:
                                                               cout<<"To create a new file, please enter a name for the file\n";
                                                               break;
                                                         case 3:
                                                                cout<<"Type in the name of the file to be modified\n";
                                                                 break;
    
                                                                 }
                                                                }
                                                              }
                      cin.get();
                      }
    }

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Code:
    for ( k = 256781; k != 256781;){
        cout<<"The password you entered is incorrect\n";
        cout<<"Please try again\n";
        cin>>a;
        cin.ignore();
    }
    Several things wrong here: (1) The for loop makes no sense. If you want something to be done while a condition is true, use a while loop. (2) Even if it did make sense, you immediately first thing set k to be the right thing, and then see whether it's the wrong thing -- and of course it isn't. (3) Even if we could somehow get into the for loop, you then don't read in to k, you read in to a, so even if they type in the right number the second time it wouldn't help them.

  3. #3
    Registered User
    Join Date
    Feb 2008
    Posts
    9
    ok thanks. ill try that

  4. #4
    Registered User
    Join Date
    Feb 2008
    Posts
    9
    fixed it!
    used the same loops from the first time you needed to enter the password. thanks tho!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 12:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 12:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 09:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21