random password generator from array

Hi guys, I am trying to write a program that will ask for users name, birthdate and pet and from those info I need to use a random number generator to select 6 char from the name and animal and 2 numbers from the birthdate. This is my code to far.

#include <iostream>
#include <math.h>
#include <cstdlib>
#include <ctime>

using namespace std;
// **************************
// Purpose of this program is to
// ask the user there name,favorite animal
// and birthday and generate a password
// base off of that
// **************************

int main () {

const int MAX = 100;
char name[MAX];
char birth[MAX];
char pet[MAX];
int password;

password = rand() % 7;
cout <<"Please enter your name :";
cout <<"Please enter your birthday :";
cout <<"Please enter your favorite pet/animal :";
cout <<" password: ", password << '\n';

return 0;

What exactly are you struggling with?

A few initial observations.

First, the line cout <<" password: ", password << '\n'; isn't going to work like you want.

Second, why is your password variable an integer? Surely if you want the password to be a combination of data you're retrieving from strings then it needs to be a string itself.

Third, is there any reason you're using C style strings, rather than the string class?
Last edited on
Topic archived. No new replies allowed.