#include #include #include struct user { char phone[50]; char ac[50]; char password[50]; float balance; }; int main() { struct user user, usr; char filename[50], phone[50], password[50], phone2[50]; FILE *fp, *fptr; int opt, choice; int amount; char cont = 'y'; do { printf("\nWhat do you want to do?"); printf("\n\n1.Register your account"); printf("\n2.Login to your account"); printf("\n\nPlease enter your choice:\t"); scanf("%d", &opt); if (opt == 1) { system("cls"); printf("\nEnter your account number:\t"); scanf("%s", user.ac); printf("Enter your phone number:\t"); scanf("%s", user.phone); printf("Enter your new password:\t"); scanf("%s", user.password); user.balance = 0; strcpy(filename, user.phone); fp = fopen(strcat(filename, ".dat"), "w"); fwrite(&user, sizeof(user), 1, fp); if (fwrite != 0) { printf("Succesfully registered"); } } else if (opt == 2) { system("cls"); printf("\nPhone No.:\t"); scanf("%s", phone); printf("Password:\t"); scanf("%s", password); fp = fopen(strcat(phone, ".dat"), "r"); if (fp == NULL) printf("Account number not registered"); else { fread(&user, sizeof(struct user), 1, fp); fclose(fp); if (!strcmp(password, user.password)) { while (cont == 'y') { system("cls"); printf("\n\tWelcome %s", user.phone); printf("\nPress 1 for balance inquiry"); printf("\nPress 2 for adding fund"); printf("\nPress 3 for cash withdraw"); printf("\nPress 4 for online transfer"); printf("\nPress 5 for changing password\n\n"); scanf("%d", &choice); switch (choice) { case 1: printf("Your current balance is Rs. %.2f", user.balance); break; case 2: system("cls"); printf("Enter amount to be added:\t"); scanf("%d", &amount); user.balance += amount; fp = fopen(phone, "w"); fwrite(&user, sizeof(struct user), 1, fp); if (fwrite != 0) printf("\n\nYou have depostied Rs.%d", amount); fclose(fp); break; case 3: system("cls"); printf("Enter withdrawl amount:\t"); scanf("%d", &amount); if (amount % 500 != 0) printf("\nSorry amount should be multiple of 500"); else if (amount > user.balance) printf("\nSorry insufficeint balance"); else { user.balance -= amount; fp = fopen(phone, "w"); fwrite(&user, sizeof(struct user), 1, fp); if (fwrite != 0) printf("\n\nYou have withdrawn Rs.%d", amount); fclose(fp); } break; case 4: printf("Please enter the phone number to trasnfer balance:\t"); scanf("%s", phone); printf("Enter the amount to transfer:\t"); scanf("%d", &amount); if (amount > user.balance) printf("\nSorry insufficent balance"); else { fptr = fopen(strcat(phone, ".dat"), "r"); if (fptr == NULL) printf("Sorry number is not registered"); else { fread(&usr, sizeof(struct user), 1, fptr); fclose(fptr); usr.balance += amount; fptr = fopen(phone, "w"); fwrite(&usr, sizeof(struct user), 1, fptr); if (fwrite != 0) { // printf("ACcount:%s",usr.ac); // printf("\npassword%s",usr.password); // printf("\nphone%s",usr.phone); // printf("\nbalance%f",usr.balance); printf("Your trasfer is completed. You have trasnfered Rs.%d to %s", amount, usr.phone); fclose(fptr); user.balance -= amount; strcpy(filename, user.phone); fp = fopen(strcat(filename, ".dat"), "w"); fwrite(&user, sizeof(struct user), 1, fp); fclose(fp); } } } break; case 5: printf("\n\nPlease enter your old password:\t"); scanf("%s", password); if (!strcmp(password, user.password)) { printf("\n\nPlease enter your new password:\n\t"); scanf("%s", password); strcpy(user.password, password); strcpy(filename, user.phone); fp = fopen(strcat(filename, ".dat"), "w"); fwrite(&user, sizeof(struct user), 1, fp); fclose(fp); printf("\nPassword succesfullly changed\n"); } else printf("\nSorry your password is wrong"); default: break; } // switch ends here printf("\n\nDo you want to continue?[y/n]:\t"); scanf("%s", &cont); } } else { printf("Invalid password"); } } printf("\n\n**Thank you for banking with ADV. bank**\n\n"); } } while (opt == 1 || opt == 2); return 0; }
What do you want to do? 1.Register your account 2.Login to your account Please enter your choice: 1 Enter your account number: 1234567890 Enter your phone number: 7566937955 Enter your new password: abc Succesfully registered What do you want to do? 1.Register your account 2.Login to your account Please enter your choice: 2 Phone No.: 7566937955 Password: abc Welcome 7566937955 Press 1 for balance inquiry Press 2 for adding fund Press 3 for cash withdraw Press 4 for online transfer Press 5 for changing password 1 Your current balance is Rs. 0.00 Do you want to continue?[y/n]: y Welcome 7566937955 Press 1 for balance inquiry Press 2 for adding fund Press 3 for cash withdraw Press 4 for online transfer Press 5 for changing password 2 Enter amount to be added: 6000 You have depostied Rs.6000 Do you want to continue?[y/n]: y Welcome 7566937955 Press 1 for balance inquiry Press 2 for adding fund Press 3 for cash withdraw Press 4 for online transfer Press 5 for changing password 1 Your current balance is Rs. 6000.00 Do you want to continue?[y/n]: y Welcome 7566937955 Press 1 for balance inquiry Press 2 for adding fund Press 3 for cash withdraw Press 4 for online transfer Press 5 for changing password 3 Enter withdrawl amount: 2000 You have withdrawn Rs.2000 Do you want to continue?[y/n]: y Welcome 7566937955 Press 1 for balance inquiry Press 2 for adding fund Press 3 for cash withdraw Press 4 for online transfer Press 5 for changing password 1 Your current balance is Rs. 4000.00 Do you want to continue?[y/n]: y Welcome 7566937955 Press 1 for balance inquiry Press 2 for adding fund Press 3 for cash withdraw Press 4 for online transfer Press 5 for changing password 5 Please enter your old password: abc Please enter your new password: riyaz Password succesfullly changed Do you want to continue?[y/n]: y Welcome 7566937955 Press 1 for balance inquiry Press 2 for adding fund Press 3 for cash withdraw Press 4 for online transfer Press 5 for changing password 4 Please enter the phone number to trasnfer balance: 987654321 Enter the amount to transfer: 1000 Sorry number is not registered Do you want to continue?[y/n]: n **Thank you for banking with ADV. bank** What do you want to do? 1.Register your account 2.Login to your account Please enter your choice: 3
0 Comments