I want to write a program in c , that manage an array of structure, bankaccount with 3 attributes: 1-number of the account, 2-account balance and 3-the account owner.
i want to write a function :
- that adds a new account whenever the user press 'a',
- the user has to type the balance and the name of owner but the account number must be assigned automatically and be incremented whenever new account is created .
This is my code until now:
#include <stdio.h>
struct bancaccount {
int num;
double balance;
char owner;
};
void maintext(); //prototype of the function that print the main text
void addaccount();
void main(void) {
struct bankaccount account[50];
maintext();
char ch;
ch = getchar();
if (ch == 'a') {
addaccount();
maintext();
}
else if (ch == 'b') {
printf("Result: show");
}
else {
printf("another key was pressed ");
}
}
void maintext() {
printf("tap one of this keys : \n"
" a : to add a new account \n"
" b : to see all accounts\n");
}
void addaccount(struct comptebanc num) {
num++; //this seems not possible it gives an error, what should i do insteed
num = num;
printf("owner name : ");
scanf("%s", account.owner);
print("balance : ");
scanf("%lf", account.balance);
printf("\n\n");
printf("Num : %d\n", account.num);
printf("Prop : %s\n", account.owner);
printf("Solde : %lf\n", account.balance);
}
How can i assign a number to every new account ? and how can i save new element in the array of the struct ? thank you for your help.
i'm still a beginner so i'm sure i made some mistakes in the fundamentals o c
numero.num++(or possiblyaccound.num++)?scanf("%s", account.owner);onchar owner;scanf("%s", account.owner);is to store astring(char array essentially) whilechar owner;is simply a singlechar.