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...