How to use values from functions in C -
i'm trying work on project i'm forbidden using global variables. in project, have next function:
int addaccount() { int id_number = 0; int id; int id_array[10]; double account_balance; double balance_array[10]; int selection = getchoice (); if (choice == 1) { if (id_number + 1 > 10) { printf("error\n"); } else { id_number = id_number + 1; printf("please come in id\n"); scanf("%d", &id); id_array[id_number - 1] = id; printf("please come in starting balance\n"); scanf("%lf", &account_balance); balance_array[id_number - 1] = account_balance; } } return; i need somehow values several of these variables , utilize them in function (particularly id, id_number, , account_balance). function need these values follows:
void displayaccounts () { int count; int selection = getchoice (); int id_number = id_number (); if (choice == 2) { (count = 0; count < id_number; count++) { printf("account #%d: id %d\n", count + 1, id_array[count]); printf("account balance %.2lf\n", balance_array[count]); } } } i know how homecoming 1 value, don't know how create multiple values usable outside of function occur. i'm trying possible or i'm going project wrong way?
use struct:
struct business relationship { int count; int id_number; int balance_array[10]; // etc etc }; pass pointer addaccount:
void addaccount(struct business relationship *account) { account->id_number = 0; // etc } and pass displayaccounts
void displayaccount(struct business relationship *account) { } eg:
struct business relationship account; addaccount(&account); displayaccount(&account); note in c need utilize struct prefix unless typedef struct.
c function variables return-value void
No comments:
Post a Comment