3 Attachment(s)
Bank account management project help
Hi. This is my first C project (I self taught myself C) and have started a basic project where users can create, update, view and manage, check and delete bank accounts. It's all terminal/command line based with no fancy GUI or graphics involved.
Basically, it looks like this:
Attachment 16063
A user will select a number to either log in or create a bank account, then they can log into that bank account. Heres the problem. I have this welcome page (when user starts the application):
Attachment 16064
When, for example, the user clicks one, they will be brought to this page:
Attachment 16065
However, when I tried the above, the welcome text won;t go away. I have two functions: Welcome() and Login(). The Welcome() function just displays the welcome page as shown above, same with the Login() function. However, when I try an if statement to see if the user either pressed 1 or 2, say they pressed one, the welcome function won't go away, It will display the welcome page and the login page together. What I want is, say when user presses 1, it will display only the login page and not the welcome page anymore. Similarily, if user presses 3 in the login page, it will send the user back to the welcome page and clear the login page. How would I do this? I had in mind, an array of function pointers, say if user presses 1, execute the Login() pointer and set the Welcome() pointer to NULL. so far, this is my code:
Code:
#include <stdio.h>
#include <string.h>
void Login()
{
char uname[20];
char pwd[20];
int accNum;
printf("\n\tLogin to see your Bank Account\n");
printf("\t Enter Account Username: ");
scanf("%[^\n]%*c", uname);
printf("\n\t Enter Password: ");
scanf("%[^\n]%*c", pwd);
printf("\n\t Enter Account Num (required): ");
scanf("%d", &accNum);
printf("\n\tYou entered '%s' for username", uname);
printf("\n\tYou entered '%s' for password", pwd);
printf("\n\tYou entered '%d' for account number", accNum);
}
void Welcome()
{
printf("\n\tWelcome to the Bank Management System\n");
printf("\t 1. Login to your account\n");
printf("\t 2. Create new account\n\n");
}
int main()
{
void(*welcome_ptr)() = &Welcome; //Declare pointer to Welcome()
void(*login_ptr)() = &Login; //Declare pointer to Login()
(*welcome_ptr)();
int choice;
printf("\t Enter your choice: ");
scanf("%d", &choice);
if(choice == 1)
{
(*login_ptr)();
}
return 0;
}