I am trying to write the above code with Structure and can not even start it(C l
ID: 3683657 • Letter: I
Question
I am trying to write the above code with Structure and can not even start it(C language).
Need help!
Project Description: In this project, you will write a program to manage a user's bank account. The program will display to following menu: 1. Create a new account (username/password) 2. Change the password 3. Cash deposit 4. Cash withdraw 5. Exit For each user, we have a structure "userType" with the following member elements username - char array (maximum size 20) password -char array (maximum size 20) vord - char array (maximum size 20) balance double - double In your program, you will display the menu and waiting for the user to enter a choice repeatedly until the user enters 5. If an invalid choice is entered, it displays an error message "Invalid Choice." and waits for the next input. The maximum number of users in this bank management system is 10. For example, userType users[10]; int userCount; If choice is 1, the program will check the number of current users in the system. If there are 10 users already, the program will display an error message and go back to the main menu. Otherwise, the program will first prompt the user to enter a username and check if the username is already used in the system or not. Then the program will prompts the user to enter a password (minimum of 6 characters). If choice is 2, the program will ask the user to enter the username. If there are no users existing in the system or the username entered do not match with any existing records, display an error message and go back to the main menu. Otherwise, ask the user to enter the old password first and then followed by the new password (minimum of 6 characters). If the old password is incorrect, display the error message and go back to the main menu. If choice is 3 or 4, the program will ask the user to enter the username and password. Once verified, the program will first display the current balance and then it prompts the user to enter the amount (must be positive) to be deposited or withdrew. Then the new balance will be displayed. If the amount to be withdrawn is greater than the current balance, an error message of "Insufficient fund" should be displayed and the program returns to the main menu.Explanation / Answer
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct userType{
char userName[20];
char password[20];
double balance;
};
int main(){
struct userType users[10];
int userCount=0;
while(1){
printf("-----------MENU----------- ");
printf(" 1- create a new account (username/password) ");
printf(" 2- change password ");
printf(" 3- cash deposit ");
printf(" 4- cash withdraw ");
printf(" 5- Exit ");
int enter;
scanf("%d",&enter);
if(enter==1){
if(userCount==10){
printf("Maximum number of users reached!! ");
}
else{
char username[20];
char password[20];
printf("Enter your username: ");
//fgets(username, sizeof(username), stdin);
scanf("%s",&username);
printf("Enter your password: ");
//fgets(password, sizeof(password), stdin);
scanf("%s",&password);
strcpy(users[userCount].userName,username);
strcpy(users[userCount].password,password);
users[userCount].balance=0.0;
userCount++;
}
}
else if(enter==2){
char username[20], oldPass[20], newPass[20];
printf("Enter your username: ");
scanf("%s",&username);
int i=0;
for(i=0;i<userCount;++i){
if(strcmp(users[i].userName,username)==0){
printf("enter old password: ");
scanf("%s",&oldPass);
if(strcmp(users[i].password,oldPass)==0){
printf("Enter the new password: ");
scanf("%s",&newPass);
strcpy(users[i].password,newPass);
}
else{
printf("Old Password entered is wrong!! ");
}
break;
}
}
if(i==userCount){
printf("No user with given input username Found!!! ");
}
}
else if(enter==3 || enter==4){
char username[20], password[20];
printf("Enter your username: ");
scanf("%s",&username);
printf("Enter your password: ");
scanf("%s",&password);
int i=0;
for(i=0;i<userCount;++i){
if(strcmp(users[i].userName,username)==0 && strcmp(users[i].password,password)==0){
printf("Current balance is: %lf ",users[i].balance);
printf("Enter the amount to deposit/withdraw: ");
double amnt;
scanf("%lf",&amnt);
if(enter==3){
users[i].balance += amnt;
printf("Your new balace is: %lf ",users[i].balance);
}
else{
if(users[i].balance < amnt){
printf("Insufficient balance to widhdraw!! ");
}
else{
users[i].balance -= amnt;
printf("Your new balace is: %lf ",users[i].balance);
}
}
break;
}
}
if(i==userCount){
printf("No user with given input username or password Found!!! ");
}
}
else if(enter==5){
break;
}
else{
printf("Invalid Input ");
}
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.