C++ I\'m trying to make a 4 digit random account number for my vector and I\'m g
ID: 3802917 • Letter: C
Question
C++
I'm trying to make a 4 digit random account number for my vector and I'm getting an error.
'a' redifinition basic types
void makeAccount(vector<account>& bank)
{
account a;
srand((unsigned int)time(NULL));
double a = rand() % 9999 + 1;
cout << "Enter Account No : ";
cout<<a.acno;
bank.push_back(a);
account temp;
cout << "Enter First Name : ";
cin >> temp.firstname;
cout << "Enter Last Name : ";
cin >> temp.lastname;
cout << "Enter The amount deposited : ";
cin >> temp.balance;
bank.push_back(temp);
}
Explanation / Answer
void makeAccount(vector<account>& bank)
{
account a;
srand((unsigned int)time(NULL));
// we cannot use variable a and it is already used by account, because of which
// there is 'a' redifinition basic types ERROR
double randomAccountNumber = rand() % 9999 + 1;
cout << "Enter Account No : ";
// for taking input from user, cin us used in c++ and for output to console cout is used.
cin >> a.acno;
bank.push_back(a);
account temp;
cout << "Enter First Name : ";
cin >> temp.firstname;
cout << "Enter Last Name : ";
cin >> temp.lastname;
cout << "Enter The amount deposited : ";
cin >> temp.balance;
bank.push_back(temp);
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.