What's new

C & C++ C Final Project Simple Bank Account System?

zldksk

Leecher
Joined
Jan 30, 2023
Posts
1
Reaction
0
Points
2
Hello po, patulong naman kung alam niyo po pano gawin huhu. Simple Bank Account System po yung kailangan kong gawin, its inclusion are (1)Balance, (2) Deposit, (3)wí†hdráw, (4)Create new user. May nagawa na po ako na code pero di ko alam pano gawin yung "create new user" tapos ano yung ilalagay sa line24 . Tapos kailangan naka loop siya.



Thank you po T_T


#include<stdio.h>

unsigned long amount = 0, deposit, wí†hdráw;
int choice, user, k;
char transaction = 'y';
int userchoice;
char username[70];

int main()
{
printf("KrAzYy BaNk");
printf("\nPress 1 to enter user");
printf("\nPress 2 to create new user");
printf("\n*****************************");
printf("\n\nEnter your choice: ");
scanf("%d", &userchoice);

if (userchoice ==1){

printf("\n\nUsername: ");
fgets(username, 70, stdin);

printf("Username: %s");
if (username == ){
printf("\n*Welcome to KrAzYy BaNk*");
printf("\n1. Check Balance");
printf("\n2. Cash wí†hdráwal");
printf("\n3. Cash Deposition");
printf("\n4. Exit");
printf("\n************************************");
printf("\n\nEnter you choice: ");
scanf("%d", &choice);

switch(choice)
{
case 1:
printf("\nYour BALANCE is %lu", amount);
break;
case 2:
printf("\n Enter the amount to wí†hdráw: ");
scanf("%lu", &wí†hdráw);
if (wí†hdráw % 100 != 0)
{
printf("\n Please enter the amount in multiples of 100");
} else if (wí†hdráw > (amount - 500))
{
printf("\n INSUFICIENT BALANCE");
}
else
{
amount = amount - wí†hdráw;
printf("\n\nPLEASE COLLECT CASH");
printf("\nYour current balance is %lu",amount);
}
break;
case 3:
printf("\nEnter the amount to DEPOSIT: ");
scanf("%lu", &deposit);
amount = amount = deposit;
printf("\nYour balance is %lu", amount);
break;
case 4:
printf("\nThank you for using KrAzYy BaNk");
break;
defualt:
printf("\nInvalid Choice");
}
printf("\n\n*KrAzYy BaNk*");
printf("\nPress 1 to enter user");
printf("\nPress 2 to create new user");
printf("\n*****************************");
printf("\n\nEnter your choice: ");
scanf("%d", &userchoice);

fflush(stdin);


return 0;
}
}
}
 
Hello! I can help you with the "Create new user" feature for your Simple Bank Account System. Here's how you can do it:

1. Declare an array of strings to store usernames.

Code:
char usernames[10][70]; // array of 10 usernames, each with max length of 70 characters

2. Modify your main function to include a loop for creating new users.

Code:
int main() {
   // your code here
   if (userchoice == 1) {
      // existing user code here
   }
   else if (userchoice == 2) {
      printf("\nEnter a username: ");
      fgets(username, 70, stdin);

      // check if username already exists
      int usernameExists = 0;
      for (int i = 0; i < 10; i++) {
         if (strcmp(username, usernames[i]) == 0) {
            printf("\nUsername already exists. Please choose a different username.\n");
            usernameExists = 1;
            break;
         }
      }

      if (!usernameExists) {
         // add new username to array
         strcpy(usernames[k], username);
         k++; // increment k for next new user

         printf("\nNew user account created successfully!\n");
      }

      // repeat loop for creating new users or entering existing user
   }
}

Explanation:
  • The code checks if the user chooses option 2 for creating a new user. If yes, the user is prompted to enter a new username using fgets().
  • The loop checks if the username already exists in the usernames array using strcmp(). If it does, the user is prompted to choose a different username.
  • If the username does not exist, the new username is added to the usernames array using strcpy() and k is incremented to keep track of the number of usernames in the array.
  • The loop is repeated to allow the user to create more new users or enter an existing user.

You can declare the usernames and k variables at the beginning of the code before the main() function. Don't forget to include string.h library for strcmp() and strcpy() functions.

Hope this helps you!
 

Similar threads

Back
Top