I'm trying to work on a project where I'm forbidden from using global variables. In my project, I have the following function:
int addAccount()
{
int ID_number = 0;
int ID;
int ID_array[10];
double account_balance;
double balance_array[10];
int choice = getChoice ();
if (choice == 1)
{
if (ID_number + 1 > 10)
{
printf("Error\n");
}
else
{
ID_number = ID_number + 1;
printf("Please enter the id\n");
scanf("%d", &ID);
ID_array[ID_number - 1] = ID;
printf("Please enter the starting balance\n");
scanf("%lf", &account_balance);
balance_array[ID_number - 1] = account_balance;
}
}
return;
I need to somehow get the values for several of these variables and use them in another function (particularly ID, ID_number, and account_balance). The function that I need these values for is as follows:
void displayAccounts ()
{
int count;
int choice = getChoice ();
int ID_number = ID_number ();
if (choice == 2)
{
for (count = 0; count < ID_number; count++)
{
printf("Account #%d: ID is %d\n", count + 1, ID_array[count]);
printf("Account balance is %.2lf\n", balance_array[count]);
}
}
}
I know how to return one value, but I don't know how to make multiple values usable outside of the function where they occur. Is what I'm trying to do even possible or is it likely that I'm going about my project the wrong way?