Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

the code should be\" C program language \" anagement sytem Preieeti Bank M Due:

ID: 3811617 • Letter: T

Question



the code should be" C program language "

anagement sytem Preieeti Bank M Due: 4/5/2017, by 10pm Preject Decription: tomanage wurer's bank account. The will weie programs In this proyect you will display following 2. Change the pasword deposit 4. Cash withdraw Exit For each user, we have structure userType" with the following member elements: username-chau amy (maximam size20 Password-charamay maximum size 2% In your program, you win display ue mene and waiting Sarae user to len adboice vser 5.1rin invalid doice is emered, it displays this bank management system is 10 For example, int userCourt, Drehoice is 1.the program wilcheck the number of arrest users in the system irdere ee 10 vaens already, the prognm display an eme message and go back tothe main menu. Otherwise, the program fini prompt enter a usemame and check used in the orro. Then the w prompts the purswoed minimum choice is the progrm win askthe user to enter the username. if e towers there in the system orte do not manch with exatingrosoods, display an error message and go back password and the followod bythe new password minimum of 6 the olapasswoed is incorrect display the show confirmation message itsuccessful emor message and go back the main menu. choice or 4, the program will ask the user to emer the userrame ad password. verified the will first display the cument balance and then it prompts tbe user to emer the amount must be positive)to be deposied or withdrew. Then the new balance will be displayed. If the amount to be is gecaer currem balance, an error message of tnsufficient fund should be displayed and the program retums to the main menu

Explanation / Answer

Code:

#include <stdio.h>
#include <string.h>
//structure for users
struct userType
{
char username[20];
char password[20];
double balance;
}users[10];
//function to create new user
int createUser(int count, struct userType users[])
{
int check = 0;
char username[20], password[20];
while (check == 0)
{
printf("Enter username (max 20 chars): ");
scanf("%s",&username);
if (count == 0)
check = 1;
else
{
for (int i = 0; i < count; i++)
{
if(strcmp(users[i].username, username) == 0)
{
printf("Username already exists. ");
check = 0;
break;
}
else
check = 1;
}
}
}
check = 0;
while (check == 0)
{
printf("Enter password (min 6, max 20 chars): ");
scanf("%s",&password);
if (strlen(password) < 6)
printf("Password should be min 6 chars ");
else
check = 1;
}
strcpy(users[count].username, username);
strcpy(users[count].password, password);
users[count].balance = 0.0;
count++;
return count;
}
//function to change password
void changePassword(int count, struct userType users[])
{
if(count == 0)
{
printf("No users available ");
return;
}
char username[20],oldpassword[20], newpassword[20];
int match = 0, usernum = -1;
printf("Please enter your username: ");
scanf("%s",&username);
for(int i = 0; i < count; i++)
{
if(strcmp(users[i].username, username) == 0)
{
match = 1;
usernum = i;
break;
}
}
if (match == 0)
{
printf("Username not found ");
return;
}
printf("Please enter old password: ");
scanf("%s",&oldpassword);
printf("Please enter new password: ");
scanf("%s",&newpassword);
  
if(strcmp(users[usernum].password, oldpassword) == 0)
{
strcpy(users[usernum].password, newpassword);
printf("Password changed successfully ");
}
else
printf("Old password incorrect ");
}
//function to deposit money
void deposit(int count, struct userType users[])
{
if(count == 0)
{
printf("No users available ");
return;
}
char username[20],password[20];
int match = 0, usernum = -1;
double deposit = -1.0;
printf("Please enter your username: ");
scanf("%s",&username);
for(int i = 0; i < count; i++)
{
if(strcmp(users[i].username, username) == 0)
{
match = 1;
usernum = i;
break;
}
}
if (match == 0)
{
printf("Username not found ");
return;
}
printf("Please enter your password: ");
scanf("%s",&password);
if(strcmp(users[usernum].password, password) == 0)
{
printf("Enter amount to be deposited: ");
scanf("%lf",&deposit);
if(deposit > 0.0)
{
users[usernum].balance += deposit;
printf("New Balance is %lf ",users[usernum].balance);
}
else
printf("Incorrect value ");
}
else
printf("Invalid password ");
}
//function to withdraw money
void withdraw(int count, struct userType users[])
{
if(count == 0)
{
printf("No users available ");
return;
}
char username[20],password[20];
int match = 0, usernum = -1;
double withdraw = -1.0;
printf("Please enter your username: ");
scanf("%s",&username);
for(int i = 0; i < count; i++)
{
if(strcmp(users[i].username, username) == 0)
{
match = 1;
usernum = i;
break;
}
}
if (match == 0)
{
printf("Username not found ");
return;
}
printf("Please enter your password: ");
scanf("%s",&password);
if(strcmp(users[usernum].password, password) == 0)
{
printf("Enter amount to be withdrawn: ");
scanf("%lf",&withdraw);
if(withdraw > 0.0 && users[usernum].balance > withdraw)
{
users[usernum].balance -= withdraw;
printf("Amount withdrawn: %lf New Balance is %lf ",withdraw,users[usernum].balance);
}
else if(withdraw > 0.0 && users[usernum].balance < withdraw)
{
printf("Insufficient funds ");
}
else
printf("Incorrect value ");
}
else
printf("Invalid password ");
}

int main()
{
int option, menu = 1, userCount = 0;
//Infinite menu till exit
while (menu == 1)
{
printf("1. Create a new account (username/password) ");
printf("2. Change the password ");
printf("3. Cash Deposit ");
printf("4. Cash Withdrawal ");
printf("5. Exit ");
scanf("%d",&option);
switch(option)
{
case 1:
if (userCount ==10) //checking for max user count
printf("Maximum user limit reached. ");
else
userCount = createUser(userCount, users);
break;
case 2:
changePassword(userCount, users);
break;
case 3:
deposit(userCount, users);
break;
case 4:
withdraw(userCount,users);
break;
case 5:
menu = 0;
break;
default:
printf("Invalid Option ");
break;
}
}

return 0;
}