Hey all.
I'm writing a simple bank program with a menu of options, and the first option is to create an account. The user enters an account number and this number is stored in the array in the first empty slot.
So for example, if the user enters 100, it will be stored in array[0]. If the user chooses to create another account and enters 101 after that, it should be stored in array[1]. And so on. The user isn't asked how many numbers they want to enter, they're just asked to enter a number and the number should be stored in an empty array.
I'm thinking this should involve a loop, but my problem is that the loops I've tried stores the first number into every single spot in the array, so the second input doesn't work.
Here's what I've tried:
int accountnum[1000];
int accnum;
cout << "Enter an account number: ";
cin >> accnum;
for(int i=0;i<1000;i++)
{
if(accountnum[i]==0)
{
accountnum[i]=accnum;
}
}
Any help would be great. Thanks.