help pls

This is a discussion on help pls within the C++ Programming forums, part of the General Programming Boards category; Code: #include <iostream> #include <iomanip> #include <conio.h> #include <math.h> #include <string> #include <ctype.h> #include <fstream> using namespace std; void password_generator(); ...

  1. #1
    Registered User
    Join Date
    Sep 2010
    Posts
    9

    help pls

    Code:
    #include <iostream>
    #include <iomanip>
    #include <conio.h>
    #include <math.h>
    #include <string>
    #include <ctype.h>
    #include <fstream>
    
    using namespace std;
     void password_generator();
     void get_information();
     void form_password();
     int length;
     struct user
     {char name[50],nickname[50],hobby[50];
      int phone_number,birthdate,ic_number;};
      user user;
    char password;
     
     
    int main() 
    {
        password_generator();
        get_information();
        form_password();
        
        getch();
        return 0;
    }
        
        void password_generator()
    {   
        cout<<"                         *Password Generator*"<<endl<<endl;
        cout<<"Please enter the length of password that the generator need to create" <<endl<< "< keyin any number from 6-14 >:";
        cin>>length;
       
        while ((length>=6)&&(length<=14))
        {cout<<"Valid"<<endl;
        break;}
        
        while ((length<6)||(length>14))
        {     
        cout<<"Invalid length entry"<<endl<<"Retype length of password:"; 
        cin>>length;
        while ((length>=6)&&(length<=14))
        {cout<<"Valid"<<endl;
        break;
        }
        }
      
        cout<<"---------------------------------------------------------"<<endl;
    }
         
        void get_information()
    {  
        
        cout<<"Please enter your name:";
        cin>>user.name;
        
        cout<<"Please enter your nick name:";
        cin>>user.nickname;
        
        cout<<"Please enter your hobby:";
        cin>>user.hobby;
        
        cout<<"Please enter your phone number:";
        cin>>user.phone_number;
    
        cout<<"Please enter your birthdate(ddmmyyyy):";
        cin>>user.birthdate;
        
        cout<<"Please enter your identity card number:";
        cin>>user.ic_number;
    }
     
    void form_password()
    {
         //
        
         char name[]="abcdefghijklmnopqrstuvwxyz0123456789";
         char password[length];
         srand (time(NULL));
         for (int i=0;i<length;i++)
         {password[i]=name[rand()%37];
         }
         cout<<"Your password is:";
         for (int y=0;y<length;y++)
         {cout<<password[y];}
         
         ofstream file_out("password.dat");
          if (file_out.fail())
        {
         cerr<<"Filename not found in disk."<<endl;
         exit(-1);
        }
        else
        {
         cout<<"\n\nExport file is successfully opened."<<"\nYou may retrive your password in the file."<<endl;
        }
         file_out<<"Your password generated is:"<<password<<endl;
         file_out.close();
         
         
       
    }

    Now, i need some help on tis...
    1st, if i wan random the information enter by the user n not "abcdefghijklmnopqrstuvwxyz0123456789"... how to change the code to link the information keyin by user to random it...
    2nd, the password generated sometime contain space in btw the password. y?
    3rd, thr will be a @ symbol when i send the password out the file... how shud i eliminate it?
    Thx for help...
    Last edited by Salem; 10-07-2010 at 05:13 AM. Reason: code tags - 8 posts, you REALLY need to start paying attention!

  2. #2
    Registered User
    Join Date
    Aug 2010
    Posts
    230
    first rename your topic title....
    secondly use codes!

  3. #3
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,538
    Random comments:
    << !! Posting Code? Read this First !! >>
    Fix lines such as
    Code:
    {cout<<"Valid"<<endl;
    break;}
    to
    Code:
    {
        cout<<"Valid"<<endl;
        break;
    }
    Use std::string instead of char and char[].
    No need to manually close files (ie, don't call close() on your streams).
    Change the thread title to something that actually describes your problem.
    Remove global variables.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Registered User
    Join Date
    Sep 2010
    Posts
    9
    how 2 change thread title?

  5. #5
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,538
    You cannot. Remember it for the future.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Registered User
    Join Date
    Sep 2010
    Posts
    33
    Q2.
    name has 36 characters, 0-35
    when rand() returns 36, or 73, or 110 etc etc
    36 mod 37 = 36 = space
    73 mod 37 = 36 = space

    so use mod 36

    *

    Sorry, but your input code is awful. You may prefer something like this:

    Code:
    //cout<<"Please enter the length of password that the generator need to create" <<endl<< "< keyin any number from 6-14 >:";
        //cin>>length;
    
        //while ((length>=6)&&(length<=14))
        //{cout<<"Valid"<<endl;
        //break;}
    
        //while ((length<6)||(length>14))
        //{
        //cout<<"Invalid length entry"<<endl<<"Retype length of password:";
        //cin>>length;
        //while ((length>=6)&&(length<=14))
        //{cout<<"Valid"<<endl;
        //break;
        //}
        //}
    
         bool valid = false;
         while (valid == false){
            cout << "Enter length of password (6-14): ";
            cin >> length;
             if ((length < 6) || (length > 14))
                cout << "Invalid input, please try again" << endl;
             else
                valid = true;
         }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. i realy need help pls...
    By kimjan in forum C++ Programming
    Replies: 6
    Last Post: 12-23-2009, 06:04 AM
  2. Basic port scanner code .. pls help ???
    By intruder in forum C Programming
    Replies: 18
    Last Post: 03-13-2003, 07:47 AM
  3. i dont know what to do. pls. help!!!!
    By Unregistered in forum C++ Programming
    Replies: 14
    Last Post: 03-14-2002, 02:24 PM
  4. help me pls..... :(
    By mocha_frap024 in forum C++ Programming
    Replies: 2
    Last Post: 02-22-2002, 09:46 AM
  5. C programming - pls pls help me
    By sally arnold in forum C Programming
    Replies: 10
    Last Post: 01-16-2002, 03:55 AM

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